Skip to content
Merged
Changes from 2 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
51 changes: 24 additions & 27 deletions packages/router-core/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1472,20 +1472,20 @@ export class RouterCore<
: this.resolvePathWithBase(fromPath, '.')

// Resolve the next params
let nextParams =
const nextParams =
dest.params === false || dest.params === null
? {}
: (dest.params ?? true) === true
? fromParams
: {
...fromParams,
...functionalUpdate(dest.params as any, fromParams),
}
: Object.assign(
fromParams,
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 ?? {},
params: nextParams,
parseCache: this.parsePathnameCache,
}).interpolatedPath

Expand All @@ -1495,23 +1495,20 @@ export class RouterCore<

// If there are any params, we need to stringify them
if (Object.keys(nextParams).length > 0) {
destRoutes
.map((route) => {
return (
route.options.params?.stringify ?? route.options.stringifyParams
)
})
.filter(Boolean)
.forEach((fn) => {
nextParams = { ...nextParams!, ...fn!(nextParams) }
})
for (const route of destRoutes) {
const fn =
route.options.params?.stringify ?? route.options.stringifyParams
if (fn) {
Object.assign(nextParams, fn(nextParams))
}
}
}

const nextPathname = interpolatePath({
// Use the original template path for interpolation
// This preserves the original parameter syntax including optional parameters
path: nextTo,
params: nextParams ?? {},
params: nextParams,
leaveWildcards: false,
leaveParams: opts.leaveParams,
decodeCharMap: this.pathParamsDecodeCharMap,
Expand All @@ -1521,20 +1518,20 @@ export class RouterCore<
// Resolve the next search
let nextSearch = fromSearch
if (opts._includeValidateSearch && this.options.search?.strict) {
let validatedSearch = {}
const validatedSearch = {}
destRoutes.forEach((route) => {
try {
if (route.options.validateSearch) {
validatedSearch = {
...validatedSearch,
...(validateSearch(route.options.validateSearch, {
if (route.options.validateSearch) {
try {
Object.assign(
validatedSearch,
validateSearch(route.options.validateSearch, {
...validatedSearch,
...nextSearch,
}) ?? {}),
}
}),
)
} catch {
// ignore errors here because they are already handled in matchRoutes
}
} catch {
// ignore errors here because they are already handled in matchRoutes
}
})
nextSearch = validatedSearch
Expand Down
Loading