From: Eduardo San Martin Morote Date: Mon, 28 Feb 2022 14:34:36 +0000 (+0100) Subject: refactor: check for edge cases too X-Git-Tag: v4.0.13~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=42f82ed5b6fbbccef4afb188edf3914ab0859a3a;p=thirdparty%2Fvuejs%2Frouter.git refactor: check for edge cases too --- diff --git a/src/matcher/index.ts b/src/matcher/index.ts index 994af7ec..ca31e86f 100644 --- a/src/matcher/index.ts +++ b/src/matcher/index.ts @@ -211,28 +211,17 @@ 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 && - !isChildOf(matcher, matchers[i]) + // Adding children with empty path should still appear before the parent + // https://github.com/vuejs/router/issues/1124 + (matcher.record.path !== matchers[i].record.path || + !isRecordChildOf(matcher, matchers[i])) ) i++ - // console.log('END i is', { i }) - // while (i < matchers.length && matcher.score <= matchers[i].score) i++ matchers.splice(i, 0, matcher) // only add the original record to the name map if (matcher.record.name && !isAliasRecord(matcher)) @@ -474,4 +463,13 @@ function checkMissingParamsInAbsolutePath( } } +function isRecordChildOf( + record: RouteRecordMatcher, + parent: RouteRecordMatcher +): boolean { + return parent.children.some( + child => child === record || isRecordChildOf(record, child) + ) +} + export type { PathParserOptions, _PathParserOptions }