@@ -119,8 +119,15 @@ function getNormalizedName(
119119 return [ location . pathname , 'url' ] ;
120120}
121121
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 [ ] ) ;
124131
125132 if ( activeTransaction && branches ) {
126133 activeTransaction . setName ( ...getNormalizedName ( routes , location , branches ) ) ;
@@ -132,8 +139,9 @@ function handleNavigation(
132139 routes : RouteObject [ ] ,
133140 navigationType : Action ,
134141 matches ?: AgnosticDataRouteMatch ,
142+ basename ?: string ,
135143) : void {
136- const branches = Array . isArray ( matches ) ? matches : _matchRoutes ( routes , location ) ;
144+ const branches = Array . isArray ( matches ) ? matches : _matchRoutes ( routes , location , basename ) ;
137145
138146 if ( _startTransactionOnLocationChange && ( navigationType === 'PUSH' || navigationType === 'POP' ) && branches ) {
139147 if ( activeTransaction ) {
@@ -254,15 +262,17 @@ export function wrapCreateBrowserRouter<
254262 TRouter extends Router < TState > = Router < TState > ,
255263> ( createRouterFunction : CreateRouterFunction < TState , TRouter > ) : CreateRouterFunction < TState , TRouter > {
256264 // `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.
257266 // 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 {
259268 const router = createRouterFunction ( routes , opts ) ;
269+ const basename = opts && opts . basename ;
260270
261271 // The initial load ends when `createBrowserRouter` is called.
262272 // This is the earliest convenient time to update the transaction name.
263273 // Callbacks to `router.subscribe` are not called for the initial load.
264274 if ( router . state . historyAction === 'POP' && activeTransaction ) {
265- updatePageloadTransaction ( router . state . location , routes ) ;
275+ updatePageloadTransaction ( router . state . location , routes , undefined , basename ) ;
266276 }
267277
268278 router . subscribe ( ( state : RouterState ) => {
@@ -273,7 +283,7 @@ export function wrapCreateBrowserRouter<
273283 ( state . historyAction === 'PUSH' || state . historyAction === 'POP' ) &&
274284 activeTransaction
275285 ) {
276- handleNavigation ( location , routes , state . historyAction ) ;
286+ handleNavigation ( location , routes , state . historyAction , undefined , basename ) ;
277287 }
278288 } ) ;
279289
0 commit comments