From: Eduardo San Martin Morote Date: Tue, 19 Aug 2025 15:02:38 +0000 (+0200) Subject: refactor: simplify resolution X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7432d653f4d79de21be4b52cd411ecd6e9a3468d;p=thirdparty%2Fvuejs%2Frouter.git refactor: simplify resolution --- diff --git a/packages/router/src/experimental/router.ts b/packages/router/src/experimental/router.ts index 4d6f9c29..f7a3caea 100644 --- a/packages/router/src/experimental/router.ts +++ b/packages/router/src/experimental/router.ts @@ -52,6 +52,7 @@ import type { RouteLocationResolved, RouteMap, RouteRecordNameGeneric, + RouteRecordRedirectOption, } from '../typed-routes' import { Lazy, @@ -180,7 +181,6 @@ export interface EXPERIMENTAL_RouterOptions_Base extends PathParserOptions { // linkInactiveClass?: string } -// TODO: non matchable and parent /** * Internal type for common properties among all kind of {@link RouteRecordRaw}. */ @@ -192,7 +192,7 @@ export interface EXPERIMENTAL_RouteRecord_Base * before any navigation guard and triggers a new navigation with the new * target location. */ - // redirect?: RouteRecordRedirectOption; + redirect?: RouteRecordRedirectOption // TODO: /** @@ -217,12 +217,6 @@ export interface EXPERIMENTAL_RouteRecord_Base */ meta?: RouteMeta - // TODO: - /** - * Array of nested routes. - */ - // children?: RouteRecordRaw[] - /** * Components to display when the URL matches this route. Allow using named views. */ @@ -247,8 +241,6 @@ export interface EXPERIMENTAL_RouteRecord_Matchable components: Record parent?: EXPERIMENTAL_RouteRecordNormalized | null - - redirect?: never } export interface EXPERIMENTAL_RouteRecord_Group @@ -261,9 +253,6 @@ export interface EXPERIMENTAL_RouteRecord_Group components?: Record parent?: EXPERIMENTAL_RouteRecordNormalized | null - - // TODO: - // redirect?: something } export type EXPERIMENTAL_RouteRecordRaw = @@ -318,9 +307,6 @@ export interface EXPERIMENTAL_RouteRecordNormalized_Matchable parent: EXPERIMENTAL_RouteRecordNormalized | null - // TODO: - // redirect?: unknown - components: Record } @@ -383,6 +369,7 @@ export function mergeRouteRecord( ) { for (const record of routeRecords) { main.meta = { ...main.meta, ...record.meta } + main.props = { ...main.props, ...record.props } } return main } @@ -624,8 +611,6 @@ export function experimental_createRouter( return !!resolver.getRecord(name) } - // TODO: replace usage with resolver.resolve() - // NOTE: to support multiple overloads type TRecord = EXPERIMENTAL_RouteRecordNormalized type _resolveArgs = @@ -662,27 +647,6 @@ export function experimental_createRouter( function resolve( ...[to, currentLocation]: _resolveArgs ): RouteLocationResolved { - // const resolve: Router['resolve'] = (rawLocation: RouteLocationRaw, currentLocation) => { - // const objectLocation = routerLocationAsObject(rawLocation) - // we create a copy to modify it later - // TODO: in the experimental version, allow configuring this - currentLocation = - // TODO: || currentRoute.value never evaluated - currentLocation && assign({}, currentLocation || currentRoute.value) - // currentLocation = assign({}, currentLocation || currentRoute.value) - - // FIXME: should this be achieved by matchers? - // remove any nullish param - // if ('params' in rawLocation) { - // const targetParams = assign({}, rawLocation.params) - // for (const key in targetParams) { - // if (targetParams[key] == null) { - // delete targetParams[key] - // } - // } - // rawLocation.params = targetParams - // } - const matchedRoute = resolver.resolve( // @ts-expect-error FIXME: incompatible types to, @@ -739,7 +703,7 @@ export function experimental_createRouter( ): RouteLocationRaw | void { const redirect = to.matched.at(-1)?.redirect if (redirect) { - return resolve( + return resolver.resolve( // @ts-expect-error: TODO: allow redirect to return the first argument of resolve or a tuple consisting of the arguments? typeof redirect === 'function' ? redirect(to, from) : redirect, from