@@ -61,6 +61,9 @@ export interface ReactRouterOptions {
61
61
62
62
type V6CompatibleVersion = '6' | '7' ;
63
63
64
+ // Keeping as a global variable for cross-usage in multiple functions
65
+ const allRoutes = new Set < RouteObject > ( ) ;
66
+
64
67
/**
65
68
* Creates a wrapCreateBrowserRouter function that can be used with all React Router v6 compatible versions.
66
69
*/
@@ -81,6 +84,10 @@ export function createV6CompatibleWrapCreateBrowserRouter<
81
84
}
82
85
83
86
return function ( routes : RouteObject [ ] , opts ?: Record < string , unknown > & { basename ?: string } ) : TRouter {
87
+ routes . forEach ( route => {
88
+ allRoutes . add ( route ) ;
89
+ } ) ;
90
+
84
91
const router = createRouterFunction ( routes , opts ) ;
85
92
const basename = opts ?. basename ;
86
93
@@ -90,7 +97,14 @@ export function createV6CompatibleWrapCreateBrowserRouter<
90
97
// This is the earliest convenient time to update the transaction name.
91
98
// Callbacks to `router.subscribe` are not called for the initial load.
92
99
if ( router . state . historyAction === 'POP' && activeRootSpan ) {
93
- updatePageloadTransaction ( activeRootSpan , router . state . location , routes , undefined , basename ) ;
100
+ updatePageloadTransaction (
101
+ activeRootSpan ,
102
+ router . state . location ,
103
+ routes ,
104
+ undefined ,
105
+ basename ,
106
+ Array . from ( allRoutes ) ,
107
+ ) ;
94
108
}
95
109
96
110
router . subscribe ( ( state : RouterState ) => {
@@ -104,6 +118,7 @@ export function createV6CompatibleWrapCreateBrowserRouter<
104
118
navigationType : state . historyAction ,
105
119
version,
106
120
basename,
121
+ allRoutes : Array . from ( allRoutes ) ,
107
122
} ) ;
108
123
} ) ;
109
124
} else {
@@ -113,6 +128,7 @@ export function createV6CompatibleWrapCreateBrowserRouter<
113
128
navigationType : state . historyAction ,
114
129
version,
115
130
basename,
131
+ allRoutes : Array . from ( allRoutes ) ,
116
132
} ) ;
117
133
}
118
134
}
@@ -149,6 +165,10 @@ export function createV6CompatibleWrapCreateMemoryRouter<
149
165
initialIndex ?: number ;
150
166
} ,
151
167
) : TRouter {
168
+ routes . forEach ( route => {
169
+ allRoutes . add ( route ) ;
170
+ } ) ;
171
+
152
172
const router = createRouterFunction ( routes , opts ) ;
153
173
const basename = opts ?. basename ;
154
174
@@ -174,7 +194,7 @@ export function createV6CompatibleWrapCreateMemoryRouter<
174
194
: router . state . location ;
175
195
176
196
if ( router . state . historyAction === 'POP' && activeRootSpan ) {
177
- updatePageloadTransaction ( activeRootSpan , location , routes , undefined , basename ) ;
197
+ updatePageloadTransaction ( activeRootSpan , location , routes , undefined , basename , Array . from ( allRoutes ) ) ;
178
198
}
179
199
180
200
router . subscribe ( ( state : RouterState ) => {
@@ -186,6 +206,7 @@ export function createV6CompatibleWrapCreateMemoryRouter<
186
206
navigationType : state . historyAction ,
187
207
version,
188
208
basename,
209
+ allRoutes : Array . from ( allRoutes ) ,
189
210
} ) ;
190
211
}
191
212
} ) ;
@@ -260,8 +281,6 @@ export function createV6CompatibleWrapUseRoutes(origUseRoutes: UseRoutes, versio
260
281
return origUseRoutes ;
261
282
}
262
283
263
- const allRoutes : Set < RouteObject > = new Set ( ) ;
264
-
265
284
const SentryRoutes : React . FC < {
266
285
children ?: React . ReactNode ;
267
286
routes : RouteObject [ ] ;
@@ -331,7 +350,6 @@ export function handleNavigation(opts: {
331
350
allRoutes ?: RouteObject [ ] ;
332
351
} ) : void {
333
352
const { location, routes, navigationType, version, matches, basename, allRoutes } = opts ;
334
-
335
353
const branches = Array . isArray ( matches ) ? matches : _matchRoutes ( routes , location , basename ) ;
336
354
337
355
const client = getClient ( ) ;
@@ -565,7 +583,7 @@ function updatePageloadTransaction(
565
583
) : void {
566
584
const branches = Array . isArray ( matches )
567
585
? matches
568
- : ( _matchRoutes ( routes , location , basename ) as unknown as RouteMatch [ ] ) ;
586
+ : ( _matchRoutes ( allRoutes || routes , location , basename ) as unknown as RouteMatch [ ] ) ;
569
587
570
588
if ( branches ) {
571
589
let name ,
@@ -581,7 +599,7 @@ function updatePageloadTransaction(
581
599
[ name , source ] = getNormalizedName ( routes , location , branches , basename ) ;
582
600
}
583
601
584
- getCurrentScope ( ) . setTransactionName ( name ) ;
602
+ getCurrentScope ( ) . setTransactionName ( name || '/' ) ;
585
603
586
604
if ( activeRootSpan ) {
587
605
activeRootSpan . updateName ( name ) ;
@@ -604,8 +622,6 @@ export function createV6CompatibleWithSentryReactRouterRouting<P extends Record<
604
622
return Routes ;
605
623
}
606
624
607
- const allRoutes : Set < RouteObject > = new Set ( ) ;
608
-
609
625
const SentryRoutes : React . FC < P > = ( props : P ) => {
610
626
const isMountRenderPass = React . useRef ( true ) ;
611
627
0 commit comments