@@ -119,8 +119,15 @@ function getNormalizedName(
119
119
return [ location . pathname , 'url' ] ;
120
120
}
121
121
122
- function updatePageloadTransaction ( location : Location , routes : RouteObject [ ] , matches ?: AgnosticDataRouteMatch ) : void {
123
- const branches = Array . isArray ( matches ) ? matches : ( _matchRoutes ( routes , location ) as unknown as RouteMatch [ ] ) ;
122
+ function updatePageloadTransaction (
123
+ location : Location ,
124
+ routes : RouteObject [ ] ,
125
+ matches ?: AgnosticDataRouteMatch ,
126
+ basename ?: string ,
127
+ ) : void {
128
+ const branches = Array . isArray ( matches )
129
+ ? matches
130
+ : ( _matchRoutes ( routes , location , basename ) as unknown as RouteMatch [ ] ) ;
124
131
125
132
if ( activeTransaction && branches ) {
126
133
activeTransaction . setName ( ...getNormalizedName ( routes , location , branches ) ) ;
@@ -132,8 +139,9 @@ function handleNavigation(
132
139
routes : RouteObject [ ] ,
133
140
navigationType : Action ,
134
141
matches ?: AgnosticDataRouteMatch ,
142
+ basename ?: string ,
135
143
) : void {
136
- const branches = Array . isArray ( matches ) ? matches : _matchRoutes ( routes , location ) ;
144
+ const branches = Array . isArray ( matches ) ? matches : _matchRoutes ( routes , location , basename ) ;
137
145
138
146
if ( _startTransactionOnLocationChange && ( navigationType === 'PUSH' || navigationType === 'POP' ) && branches ) {
139
147
if ( activeTransaction ) {
@@ -254,15 +262,17 @@ export function wrapCreateBrowserRouter<
254
262
TRouter extends Router < TState > = Router < TState > ,
255
263
> ( createRouterFunction : CreateRouterFunction < TState , TRouter > ) : CreateRouterFunction < TState , TRouter > {
256
264
// `opts` for createBrowserHistory and createMemoryHistory are different, but also not relevant for us at the moment.
265
+ // `basename` is the only option that is relevant for us, and it is the same for all.
257
266
// eslint-disable-next-line @typescript-eslint/no-explicit-any
258
- return function ( routes : RouteObject [ ] , opts ?: any ) : TRouter {
267
+ return function ( routes : RouteObject [ ] , opts ?: Record < string , any > & { basename ?: string } ) : TRouter {
259
268
const router = createRouterFunction ( routes , opts ) ;
269
+ const basename = opts && opts . basename ;
260
270
261
271
// The initial load ends when `createBrowserRouter` is called.
262
272
// This is the earliest convenient time to update the transaction name.
263
273
// Callbacks to `router.subscribe` are not called for the initial load.
264
274
if ( router . state . historyAction === 'POP' && activeTransaction ) {
265
- updatePageloadTransaction ( router . state . location , routes ) ;
275
+ updatePageloadTransaction ( router . state . location , routes , undefined , basename ) ;
266
276
}
267
277
268
278
router . subscribe ( ( state : RouterState ) => {
@@ -273,7 +283,7 @@ export function wrapCreateBrowserRouter<
273
283
( state . historyAction === 'PUSH' || state . historyAction === 'POP' ) &&
274
284
activeTransaction
275
285
) {
276
- handleNavigation ( location , routes , state . historyAction ) ;
286
+ handleNavigation ( location , routes , state . historyAction , undefined , basename ) ;
277
287
}
278
288
} ) ;
279
289
0 commit comments