Skip to content

Commit

Permalink
fix: fix mods in aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Sep 13, 2024
1 parent c7dd2a1 commit 5e20afb
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions packages/router/src/matcher/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,28 +88,30 @@ export function createRouterMatcher(
mainNormalizedRecord.aliasOf = originalRecord && originalRecord.record
const options: PathParserOptions = mergeOptions(globalOptions, record)
// generate an array of records to correctly handle aliases
const normalizedRecords: (typeof mainNormalizedRecord)[] = [
mainNormalizedRecord,
]
const normalizedRecords: RouteRecordNormalized[] = [mainNormalizedRecord]
if ('alias' in record) {
const aliases =
typeof record.alias === 'string' ? [record.alias] : record.alias!
for (const alias of aliases) {
normalizedRecords.push(
assign({}, mainNormalizedRecord, {
// this allows us to hold a copy of the `components` option
// so that async components cache is hold on the original record
components: originalRecord
? originalRecord.record.components
: mainNormalizedRecord.components,
path: alias,
// we might be the child of an alias
aliasOf: originalRecord
? originalRecord.record
: mainNormalizedRecord,
// the aliases are always of the same kind as the original since they
// are defined on the same record
}) as typeof mainNormalizedRecord
// we need to normalize again to ensure the `mods` property
// being non enumerable
normalizeRouteRecord(
assign({}, mainNormalizedRecord, {
// this allows us to hold a copy of the `components` option
// so that async components cache is hold on the original record
components: originalRecord
? originalRecord.record.components
: mainNormalizedRecord.components,
path: alias,
// we might be the child of an alias
aliasOf: originalRecord
? originalRecord.record
: mainNormalizedRecord,
// the aliases are always of the same kind as the original since they
// are defined on the same record
})
)
)
}
}
Expand Down Expand Up @@ -379,14 +381,14 @@ function paramsFromLocation(
* @returns the normalized version
*/
export function normalizeRouteRecord(
record: RouteRecordRaw
record: RouteRecordRaw & { aliasOf?: RouteRecordNormalized }
): RouteRecordNormalized {
const normalized: Omit<RouteRecordNormalized, 'mods'> = {
path: record.path,
redirect: record.redirect,
name: record.name,
meta: record.meta || {},
aliasOf: undefined,
aliasOf: record.aliasOf,
beforeEnter: record.beforeEnter,
props: normalizeRecordProps(record),
children: record.children || [],
Expand Down

0 comments on commit 5e20afb

Please sign in to comment.