Skip to content

Commit

Permalink
fix(matcher): add child before parent when using addRoute
Browse files Browse the repository at this point in the history
  • Loading branch information
Namysh authored and posva committed Feb 28, 2022
1 parent f951b85 commit 8744bba
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/matcher/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down

0 comments on commit 8744bba

Please sign in to comment.