]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
fix: fix mods in aliases
authorEduardo San Martin Morote <posva13@gmail.com>
Fri, 13 Sep 2024 06:40:15 +0000 (08:40 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Fri, 13 Sep 2024 06:40:15 +0000 (08:40 +0200)
packages/router/src/matcher/index.ts

index c80c83e55dcd36c318fb09d5230faaad90e47f5b..530630230c4fe55e4a0ab21f26a392f656c6e7e3 100644 (file)
@@ -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
+            })
+          )
         )
       }
     }
@@ -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 || [],