From: Eduardo San Martin Morote Date: Fri, 25 Jul 2025 12:36:11 +0000 (+0200) Subject: refactor: loose children property in normalized records X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d238f6df7c266bedb5bbf78e6a95dd9462ec5df2;p=thirdparty%2Fvuejs%2Frouter.git refactor: loose children property in normalized records --- diff --git a/packages/router/src/experimental/router.ts b/packages/router/src/experimental/router.ts index 2f9cb342..2a7c7606 100644 --- a/packages/router/src/experimental/router.ts +++ b/packages/router/src/experimental/router.ts @@ -328,14 +328,21 @@ export type EXPERIMENTAL_RouteRecordNormalized = | EXPERIMENTAL_RouteRecordNormalized_Matchable | EXPERIMENTAL_RouteRecordNormalized_Group +export function normalizeRouteRecord( + record: EXPERIMENTAL_RouteRecord_Group +): EXPERIMENTAL_RouteRecordNormalized_Group export function normalizeRouteRecord( record: EXPERIMENTAL_RouteRecord_Matchable -): EXPERIMENTAL_RouteRecordNormalized_Matchable { +): EXPERIMENTAL_RouteRecordNormalized_Matchable +export function normalizeRouteRecord( + record: EXPERIMENTAL_RouteRecord_Matchable | EXPERIMENTAL_RouteRecord_Group +): + | EXPERIMENTAL_RouteRecordNormalized_Matchable + | EXPERIMENTAL_RouteRecordNormalized_Group { // we can't define mods if we want to call defineProperty later - const normalizedRecord: Omit< - EXPERIMENTAL_RouteRecordNormalized_Matchable, - 'mods' - > = { + const normalizedRecord: + | Omit + | Omit = { meta: {}, // must be defined as non enumerable because it contains modules // mods: {}, @@ -354,7 +361,9 @@ export function normalizeRouteRecord( value: {}, }) - return normalizedRecord as EXPERIMENTAL_RouteRecordNormalized_Matchable + return normalizedRecord as + | EXPERIMENTAL_RouteRecordNormalized_Matchable + | EXPERIMENTAL_RouteRecordNormalized_Group } // TODO: probably need some generic types @@ -671,9 +680,9 @@ export function experimental_createRouter( // } const matchedRoute = resolver.resolve( - // incompatible types + // FIXME: incompatible types rawLocation as any, - // incompatible `matched` requires casting + // FIXME: incompatible `matched` requires casting currentLocation as any ) const href = routerHistory.createHref(matchedRoute.fullPath) @@ -779,7 +788,8 @@ export function experimental_createRouter( const from = currentRoute.value const data: HistoryState | undefined = (to as RouteLocationOptions).state const force: boolean | undefined = (to as RouteLocationOptions).force - const replace = (to as RouteLocationOptions).replace ?? _replace + const replace = targetLocation.replace ?? _replace + console.log({ replace }) const shouldRedirect = handleRedirectRecord(targetLocation) diff --git a/packages/router/src/navigationGuards.ts b/packages/router/src/navigationGuards.ts index 4904788a..a2be525a 100644 --- a/packages/router/src/navigationGuards.ts +++ b/packages/router/src/navigationGuards.ts @@ -241,7 +241,13 @@ export function extractComponentsGuards( const guards: Array<() => Promise> = [] for (const record of matched) { - if (__DEV__ && !record.components && !record.children.length) { + if ( + __DEV__ && + !record.components && + // in the nex records, there is no children, only parents + record.children && + !record.children.length + ) { warn( `Record with path "${record.path}" is either missing a "component(s)"` + ` or "children" property.`