]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
fix(matcher): add child before parent when using `addRoute`
authorNamysh <contact@willytardy.com>
Fri, 25 Feb 2022 18:01:12 +0000 (19:01 +0100)
committerEduardo San Martin Morote <posva@users.noreply.github.com>
Mon, 28 Feb 2022 14:37:47 +0000 (15:37 +0100)
src/matcher/index.ts

index 18b752c90ff6f2fe7e3632ff4d8f9f91b1978639..994af7ec33b5296da74e41f840c3392df411e933 100644 (file)
@@ -211,12 +211,24 @@ export function createRouterMatcher(
     return matchers
   }
 
+  function isChildOf(
+    child: RouteRecordMatcher,
+    parent: RouteRecordMatcher
+  ): Boolean {
+    return parent.children.some(currChild => {
+      if (currChild === child) return true
+
+      return isChildOf(child, currChild)
+    })
+  }
+
   function insertMatcher(matcher: RouteRecordMatcher) {
     let i = 0
     // console.log('i is', { i })
     while (
       i < matchers.length &&
-      comparePathParserScore(matcher, matchers[i]) >= 0
+      comparePathParserScore(matcher, matchers[i]) >= 0 &&
+      !isChildOf(matcher, matchers[i])
     )
       i++
     // console.log('END i is', { i })