Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 11 additions & 23 deletions packages/router-core/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1852,40 +1852,30 @@ export class RouterCore<
functionalUpdate(dest.params as any, fromParams),
)

// Interpolate the path first to get the actual resolved path, then match against that
const interpolatedNextTo = interpolatePath({
path: nextTo,
params: nextParams,
decoder: this.pathParamsDecoder,
server: this.isServer,
}).interpolatedPath

// Use lightweight getMatchedRoutes instead of matchRoutesInternal
// This avoids creating full match objects (AbortController, ControlledPromise, etc.)
// which are expensive and not needed for buildLocation
const destMatchResult = this.getMatchedRoutes(interpolatedNextTo)
const destMatchResult = this.getMatchedRoutes(nextTo)
let destRoutes = destMatchResult.matchedRoutes

// Compute globalNotFoundRouteId using the same logic as matchRoutesInternal
const isGlobalNotFound = destMatchResult.foundRoute
? destMatchResult.foundRoute.path !== '/' &&
destMatchResult.routeParams['**']
: trimPathRight(interpolatedNextTo)
const isGlobalNotFound =
!destMatchResult.foundRoute ||
(destMatchResult.foundRoute.path !== '/' &&
destMatchResult.routeParams['**'])

if (isGlobalNotFound && this.options.notFoundRoute) {
destRoutes = [...destRoutes, this.options.notFoundRoute]
}

// If there are any params, we need to stringify them
let changedParams = false
if (Object.keys(nextParams).length > 0) {
for (const route of destRoutes) {
const fn =
route.options.params?.stringify ?? route.options.stringifyParams
if (fn) {
try {
Object.assign(nextParams, fn(nextParams))
changedParams = true
} catch {
// Ignore errors here. When a paired parseParams is defined,
// extractStrictParams will re-throw during route matching,
Expand All @@ -1902,14 +1892,12 @@ export class RouterCore<
// This preserves the original parameter syntax including optional parameters
nextTo
: decodePath(
!changedParams
? interpolatedNextTo
: interpolatePath({
path: nextTo,
params: nextParams,
decoder: this.pathParamsDecoder,
server: this.isServer,
}).interpolatedPath,
interpolatePath({
path: nextTo,
params: nextParams,
decoder: this.pathParamsDecoder,
server: this.isServer,
}).interpolatedPath,
).path

// Resolve the next search
Expand Down
Loading