From: Namysh Date: Fri, 25 Feb 2022 18:01:12 +0000 (+0100) Subject: fix(matcher): add child before parent when using `addRoute` X-Git-Tag: v4.0.13~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8744bbae7789e236e5308f939fb4b2d946a8ca6d;p=thirdparty%2Fvuejs%2Frouter.git fix(matcher): add child before parent when using `addRoute` --- diff --git a/src/matcher/index.ts b/src/matcher/index.ts index 18b752c9..994af7ec 100644 --- a/src/matcher/index.ts +++ b/src/matcher/index.ts @@ -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 })