@@ -84,13 +84,7 @@ export function createV6CompatibleWrapCreateBrowserRouter<
8484 }
8585
8686 return function ( routes : RouteObject [ ] , opts ?: Record < string , unknown > & { basename ?: string } ) : TRouter {
87- routes . forEach ( route => {
88- const extractedChildRoutes = getChildRoutesRecursively ( route ) ;
89-
90- extractedChildRoutes . forEach ( r => {
91- allRoutes . add ( r ) ;
92- } ) ;
93- } ) ;
87+ addRoutesToAllRoutes ( routes ) ;
9488
9589 const router = createRouterFunction ( routes , opts ) ;
9690 const basename = opts ?. basename ;
@@ -169,13 +163,7 @@ export function createV6CompatibleWrapCreateMemoryRouter<
169163 initialIndex ?: number ;
170164 } ,
171165 ) : TRouter {
172- routes . forEach ( route => {
173- const extractedChildRoutes = getChildRoutesRecursively ( route ) ;
174-
175- extractedChildRoutes . forEach ( r => {
176- allRoutes . add ( r ) ;
177- } ) ;
178- } ) ;
166+ addRoutesToAllRoutes ( routes ) ;
179167
180168 const router = createRouterFunction ( routes , opts ) ;
181169 const basename = opts ?. basename ;
@@ -311,13 +299,7 @@ export function createV6CompatibleWrapUseRoutes(origUseRoutes: UseRoutes, versio
311299 typeof stableLocationParam === 'string' ? { pathname : stableLocationParam } : stableLocationParam ;
312300
313301 if ( isMountRenderPass . current ) {
314- routes . forEach ( route => {
315- const extractedChildRoutes = getChildRoutesRecursively ( route ) ;
316-
317- extractedChildRoutes . forEach ( r => {
318- allRoutes . add ( r ) ;
319- } ) ;
320- } ) ;
302+ addRoutesToAllRoutes ( routes ) ;
321303
322304 updatePageloadTransaction (
323305 getActiveRootSpan ( ) ,
@@ -458,6 +440,17 @@ function locationIsInsideDescendantRoute(location: Location, routes: RouteObject
458440 return false ;
459441}
460442
443+ function addRoutesToAllRoutes ( routes : RouteObject [ ] ) : void {
444+ routes . forEach ( route => {
445+ const extractedChildRoutes = getChildRoutesRecursively ( route ) ;
446+
447+ extractedChildRoutes . forEach ( r => {
448+ allRoutes . add ( r ) ;
449+ } ) ;
450+ } ) ;
451+ }
452+
453+
461454function getChildRoutesRecursively ( route : RouteObject , allRoutes : Set < RouteObject > = new Set ( ) ) : Set < RouteObject > {
462455 if ( ! allRoutes . has ( route ) ) {
463456 allRoutes . add ( route ) ;
@@ -648,13 +641,7 @@ export function createV6CompatibleWithSentryReactRouterRouting<P extends Record<
648641 const routes = _createRoutesFromChildren ( props . children ) as RouteObject [ ] ;
649642
650643 if ( isMountRenderPass . current ) {
651- routes . forEach ( route => {
652- const extractedChildRoutes = getChildRoutesRecursively ( route ) ;
653-
654- extractedChildRoutes . forEach ( r => {
655- allRoutes . add ( r ) ;
656- } ) ;
657- } ) ;
644+ addRoutesToAllRoutes ( routes ) ;
658645
659646 updatePageloadTransaction ( getActiveRootSpan ( ) , location , routes , undefined , undefined , Array . from ( allRoutes ) ) ;
660647 isMountRenderPass . current = false ;
0 commit comments