Skip to content

Commit 5e20afb

Browse files
committed
fix: fix mods in aliases
1 parent c7dd2a1 commit 5e20afb

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

packages/router/src/matcher/index.ts

+21-19
Original file line numberDiff line numberDiff line change
@@ -88,28 +88,30 @@ export function createRouterMatcher(
8888
mainNormalizedRecord.aliasOf = originalRecord && originalRecord.record
8989
const options: PathParserOptions = mergeOptions(globalOptions, record)
9090
// generate an array of records to correctly handle aliases
91-
const normalizedRecords: (typeof mainNormalizedRecord)[] = [
92-
mainNormalizedRecord,
93-
]
91+
const normalizedRecords: RouteRecordNormalized[] = [mainNormalizedRecord]
9492
if ('alias' in record) {
9593
const aliases =
9694
typeof record.alias === 'string' ? [record.alias] : record.alias!
9795
for (const alias of aliases) {
9896
normalizedRecords.push(
99-
assign({}, mainNormalizedRecord, {
100-
// this allows us to hold a copy of the `components` option
101-
// so that async components cache is hold on the original record
102-
components: originalRecord
103-
? originalRecord.record.components
104-
: mainNormalizedRecord.components,
105-
path: alias,
106-
// we might be the child of an alias
107-
aliasOf: originalRecord
108-
? originalRecord.record
109-
: mainNormalizedRecord,
110-
// the aliases are always of the same kind as the original since they
111-
// are defined on the same record
112-
}) as typeof mainNormalizedRecord
97+
// we need to normalize again to ensure the `mods` property
98+
// being non enumerable
99+
normalizeRouteRecord(
100+
assign({}, mainNormalizedRecord, {
101+
// this allows us to hold a copy of the `components` option
102+
// so that async components cache is hold on the original record
103+
components: originalRecord
104+
? originalRecord.record.components
105+
: mainNormalizedRecord.components,
106+
path: alias,
107+
// we might be the child of an alias
108+
aliasOf: originalRecord
109+
? originalRecord.record
110+
: mainNormalizedRecord,
111+
// the aliases are always of the same kind as the original since they
112+
// are defined on the same record
113+
})
114+
)
113115
)
114116
}
115117
}
@@ -379,14 +381,14 @@ function paramsFromLocation(
379381
* @returns the normalized version
380382
*/
381383
export function normalizeRouteRecord(
382-
record: RouteRecordRaw
384+
record: RouteRecordRaw & { aliasOf?: RouteRecordNormalized }
383385
): RouteRecordNormalized {
384386
const normalized: Omit<RouteRecordNormalized, 'mods'> = {
385387
path: record.path,
386388
redirect: record.redirect,
387389
name: record.name,
388390
meta: record.meta || {},
389-
aliasOf: undefined,
391+
aliasOf: record.aliasOf,
390392
beforeEnter: record.beforeEnter,
391393
props: normalizeRecordProps(record),
392394
children: record.children || [],

0 commit comments

Comments
 (0)