@@ -1330,22 +1330,9 @@ export class RouterCore<
13301330 }
13311331 }
13321332
1333- globalNotFoundRouteId = ( ( ) => {
1334- if ( ! isGlobalNotFound ) {
1335- return undefined
1336- }
1337-
1338- if ( this . options . notFoundMode !== 'root' ) {
1339- for ( let i = matchedRoutes . length - 1 ; i >= 0 ; i -- ) {
1340- const route = matchedRoutes [ i ] !
1341- if ( route . children ) {
1342- return route . id
1343- }
1344- }
1345- }
1346-
1347- return rootRouteId
1348- } ) ( )
1333+ globalNotFoundRouteId = isGlobalNotFound
1334+ ? findGlobalNotFoundRouteId ( this . options . notFoundMode , matchedRoutes )
1335+ : undefined
13491336 }
13501337
13511338 const matches : Array < AnyRouteMatch > = [ ]
@@ -1792,19 +1779,11 @@ export class RouterCore<
17921779 if ( isGlobalNotFound ) {
17931780 if ( this . options . notFoundRoute ) {
17941781 globalNotFoundRouteId = this . options . notFoundRoute . id
1795- } else if ( this . options . notFoundMode !== 'root' ) {
1796- for ( let i = destRoutes . length - 1 ; i >= 0 ; i -- ) {
1797- const route = destRoutes [ i ] !
1798- if ( route . children ) {
1799- globalNotFoundRouteId = route . id
1800- break
1801- }
1802- }
1803- if ( ! globalNotFoundRouteId ) {
1804- globalNotFoundRouteId = rootRouteId
1805- }
18061782 } else {
1807- globalNotFoundRouteId = rootRouteId
1783+ globalNotFoundRouteId = findGlobalNotFoundRouteId (
1784+ this . options . notFoundMode ,
1785+ destRoutes ,
1786+ )
18081787 }
18091788 }
18101789
@@ -3173,3 +3152,18 @@ function applySearchMiddleware({
31733152 // Start applying middlewares
31743153 return applyNext ( 0 , search )
31753154}
3155+
3156+ function findGlobalNotFoundRouteId (
3157+ notFoundMode : 'root' | 'fuzzy' | undefined ,
3158+ routes : ReadonlyArray < AnyRoute > ,
3159+ ) {
3160+ if ( notFoundMode !== 'root' ) {
3161+ for ( let i = routes . length - 1 ; i >= 0 ; i -- ) {
3162+ const route = routes [ i ] !
3163+ if ( route . children ) {
3164+ return route . id
3165+ }
3166+ }
3167+ }
3168+ return rootRouteId
3169+ }
0 commit comments