@@ -896,6 +896,7 @@ export class RouterCore<
896896 rewrite ?: LocationRewrite
897897 origin ?: string
898898 latestLocation ! : ParsedLocation < FullSearchSchema < TRouteTree > >
899+ pendingBuiltLocation ?: ParsedLocation < FullSearchSchema < TRouteTree > >
899900 basepath ! : string
900901 routeTree ! : TRouteTree
901902 routesById ! : RoutesById < TRouteTree >
@@ -1593,7 +1594,8 @@ export class RouterCore<
15931594 } = { } ,
15941595 ) : ParsedLocation => {
15951596 // We allow the caller to override the current location
1596- const currentLocation = dest . _fromLocation || this . latestLocation
1597+ const currentLocation =
1598+ dest . _fromLocation || this . pendingBuiltLocation || this . latestLocation
15971599
15981600 const allCurrentLocationMatches = this . matchRoutes ( currentLocation , {
15991601 _buildLocation : true ,
@@ -1956,14 +1958,28 @@ export class RouterCore<
19561958 _includeValidateSearch : true ,
19571959 } )
19581960
1959- return this . commitLocation ( {
1961+ this . pendingBuiltLocation = location as ParsedLocation <
1962+ FullSearchSchema < TRouteTree >
1963+ >
1964+
1965+ const commitPromise = this . commitLocation ( {
19601966 ...location ,
19611967 viewTransition,
19621968 replace,
19631969 resetScroll,
19641970 hashScrollIntoView,
19651971 ignoreBlocker,
19661972 } )
1973+
1974+ // Clear pending location after commit starts
1975+ // We do this on next microtask to allow synchronous navigate calls to chain
1976+ Promise . resolve ( ) . then ( ( ) => {
1977+ if ( this . pendingBuiltLocation === location ) {
1978+ this . pendingBuiltLocation = undefined
1979+ }
1980+ } )
1981+
1982+ return commitPromise
19671983 }
19681984
19691985 /**
0 commit comments