@@ -100,7 +100,13 @@ export function createV6CompatibleWrapCreateBrowserRouter<
100100 router . subscribe ( ( state : RouterState ) => {
101101 const location = state . location ;
102102 if ( state . historyAction === 'PUSH' || state . historyAction === 'POP' ) {
103- handleNavigation ( location , routes , state . historyAction , version , undefined , basename ) ;
103+ handleNavigation ( {
104+ location,
105+ routes,
106+ navigationType : state . historyAction ,
107+ version,
108+ basename,
109+ } ) ;
104110 }
105111 } ) ;
106112
@@ -207,7 +213,13 @@ export function createV6CompatibleWrapUseRoutes(origUseRoutes: UseRoutes, versio
207213 updatePageloadTransaction ( getActiveRootSpan ( ) , normalizedLocation , routes , undefined , undefined , allRoutes ) ;
208214 isMountRenderPass . current = false ;
209215 } else {
210- handleNavigation ( normalizedLocation , routes , navigationType , version , undefined , undefined , allRoutes ) ;
216+ handleNavigation ( {
217+ location : normalizedLocation ,
218+ routes,
219+ navigationType,
220+ version,
221+ allRoutes,
222+ } ) ;
211223 }
212224 } , [ navigationType , stableLocationParam ] ) ;
213225
@@ -220,15 +232,17 @@ export function createV6CompatibleWrapUseRoutes(origUseRoutes: UseRoutes, versio
220232 } ;
221233}
222234
223- export function handleNavigation (
224- location : Location ,
225- routes : RouteObject [ ] ,
226- navigationType : Action ,
227- version : V6CompatibleVersion ,
228- matches ?: AgnosticDataRouteMatch ,
229- basename ?: string ,
230- allRoutes ?: RouteObject [ ] ,
231- ) : void {
235+ export function handleNavigation ( opts : {
236+ location : Location ;
237+ routes : RouteObject [ ] ;
238+ navigationType : Action ;
239+ version : V6CompatibleVersion ;
240+ matches ?: AgnosticDataRouteMatch ;
241+ basename ?: string ;
242+ allRoutes ?: RouteObject [ ] ;
243+ } ) : void {
244+ const { location, routes, navigationType, version, matches, basename, allRoutes } = opts ;
245+
232246 const branches = Array . isArray ( matches ) ? matches : _matchRoutes ( routes , location , basename ) ;
233247
234248 const client = getClient ( ) ;
@@ -364,24 +378,26 @@ function prefixWithSlash(path: string): string {
364378function rebuildRoutePathFromAllRoutes ( allRoutes : RouteObject [ ] , location : Location ) : string {
365379 const matchedRoutes = _matchRoutes ( allRoutes , location ) as RouteMatch [ ] ;
366380
367- if ( matchedRoutes ) {
368- for ( const match of matchedRoutes ) {
369- if ( match . route . path && match . route . path !== '*' ) {
370- const path = pickPath ( match ) ;
371- const strippedPath = stripBasenameFromPathname ( location . pathname , prefixWithSlash ( match . pathnameBase ) ) ;
372-
373- return trimSlash (
374- trimSlash ( path || '' ) +
375- prefixWithSlash (
376- rebuildRoutePathFromAllRoutes (
377- allRoutes . filter ( route => route !== match . route ) ,
378- {
379- pathname : strippedPath ,
380- } ,
381- ) ,
381+ if ( ! matchedRoutes || matchedRoutes . length === 0 ) {
382+ return '' ;
383+ }
384+
385+ for ( const match of matchedRoutes ) {
386+ if ( match . route . path && match . route . path !== '*' ) {
387+ const path = pickPath ( match ) ;
388+ const strippedPath = stripBasenameFromPathname ( location . pathname , prefixWithSlash ( match . pathnameBase ) ) ;
389+
390+ return trimSlash (
391+ trimSlash ( path || '' ) +
392+ prefixWithSlash (
393+ rebuildRoutePathFromAllRoutes (
394+ allRoutes . filter ( route => route !== match . route ) ,
395+ {
396+ pathname : strippedPath ,
397+ } ,
382398 ) ,
383- ) ;
384- }
399+ ) ,
400+ ) ;
385401 }
386402 }
387403
@@ -517,7 +533,13 @@ export function createV6CompatibleWithSentryReactRouterRouting<P extends Record<
517533 updatePageloadTransaction ( getActiveRootSpan ( ) , location , routes , undefined , undefined , allRoutes ) ;
518534 isMountRenderPass . current = false ;
519535 } else {
520- handleNavigation ( location , routes , navigationType , version , undefined , undefined , allRoutes ) ;
536+ handleNavigation ( {
537+ location,
538+ routes,
539+ navigationType,
540+ version,
541+ allRoutes,
542+ } ) ;
521543 }
522544 } ,
523545 // `props.children` is purposely not included in the dependency array, because we do not want to re-run this effect
0 commit comments