@@ -84,13 +84,7 @@ export function createV6CompatibleWrapCreateBrowserRouter<
84
84
}
85
85
86
86
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 ) ;
94
88
95
89
const router = createRouterFunction ( routes , opts ) ;
96
90
const basename = opts ?. basename ;
@@ -169,13 +163,7 @@ export function createV6CompatibleWrapCreateMemoryRouter<
169
163
initialIndex ?: number ;
170
164
} ,
171
165
) : TRouter {
172
- routes . forEach ( route => {
173
- const extractedChildRoutes = getChildRoutesRecursively ( route ) ;
174
-
175
- extractedChildRoutes . forEach ( r => {
176
- allRoutes . add ( r ) ;
177
- } ) ;
178
- } ) ;
166
+ addRoutesToAllRoutes ( routes ) ;
179
167
180
168
const router = createRouterFunction ( routes , opts ) ;
181
169
const basename = opts ?. basename ;
@@ -311,13 +299,7 @@ export function createV6CompatibleWrapUseRoutes(origUseRoutes: UseRoutes, versio
311
299
typeof stableLocationParam === 'string' ? { pathname : stableLocationParam } : stableLocationParam ;
312
300
313
301
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 ) ;
321
303
322
304
updatePageloadTransaction (
323
305
getActiveRootSpan ( ) ,
@@ -458,6 +440,17 @@ function locationIsInsideDescendantRoute(location: Location, routes: RouteObject
458
440
return false ;
459
441
}
460
442
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
+
461
454
function getChildRoutesRecursively ( route : RouteObject , allRoutes : Set < RouteObject > = new Set ( ) ) : Set < RouteObject > {
462
455
if ( ! allRoutes . has ( route ) ) {
463
456
allRoutes . add ( route ) ;
@@ -648,13 +641,7 @@ export function createV6CompatibleWithSentryReactRouterRouting<P extends Record<
648
641
const routes = _createRoutesFromChildren ( props . children ) as RouteObject [ ] ;
649
642
650
643
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 ) ;
658
645
659
646
updatePageloadTransaction ( getActiveRootSpan ( ) , location , routes , undefined , undefined , Array . from ( allRoutes ) ) ;
660
647
isMountRenderPass . current = false ;
0 commit comments