]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
fix(matcher): correct check when removing existing records on add
authorEduardo San Martin Morote <posva13@gmail.com>
Mon, 25 May 2020 08:17:21 +0000 (10:17 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Mon, 25 May 2020 08:17:21 +0000 (10:17 +0200)
src/matcher/index.ts

index ab02038d7856754d596f12a66c7b6e730ebdccc3..de894a29e3d28b831831600e02973de616853af2 100644 (file)
@@ -118,6 +118,11 @@ export function createRouterMatcher(
         // otherwise, the first record is the original and others are aliases
         originalMatcher = originalMatcher || matcher
         if (originalMatcher !== matcher) originalMatcher.alias.push(matcher)
+
+        // remove the route if named and only for the top record (avoid in nested calls)
+        // this works because the original record is the first one
+        if (isRootAdd && record.name && !isAliasRecord(matcher))
+          removeRoute(record.name)
       }
 
       // only non redirect records have children
@@ -136,9 +141,6 @@ export function createRouterMatcher(
       // other alias (if any) need to reference this record when adding children
       originalRecord = originalRecord || matcher
 
-      // remove the route if named and only for the top record (avoid in nested calls)
-      if (isRootAdd && record.name) removeRoute(record.name)
-
       insertMatcher(matcher)
     }