Skip to content
Open
Show file tree
Hide file tree
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
16 changes: 12 additions & 4 deletions packages/router-core/src/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,10 @@ export function resolvePath({
interface InterpolatePathOptions {
path?: string
params: Record<string, unknown>
// Map of encoded chars to decoded chars (e.g. '%40' -> '@') that should remain decoded in path params
/** Map of encoded chars to decoded chars (e.g. '%40' -> '@') that should remain decoded in path params */
decodeCharMap?: Map<string, string>
/** whether to encode the interpolated params (defaults: true) */
encode?: boolean
}

type InterPolatePathResult = {
Expand Down Expand Up @@ -248,6 +250,7 @@ export function interpolatePath({
path,
params,
decodeCharMap,
encode = true,
}: InterpolatePathOptions): InterPolatePathResult {
// Tracking if any params are missing in the `params` object
// when interpolating the path
Expand Down Expand Up @@ -298,7 +301,9 @@ export function interpolatePath({
continue
}

const value = encodeParam('_splat', params, decodeCharMap)
const value = encode
? encodeParam('_splat', params, decodeCharMap)
: params._splat
joined += '/' + prefix + value + suffix
continue
}
Expand All @@ -312,7 +317,9 @@ export function interpolatePath({

const prefix = path.substring(start, segment[1])
const suffix = path.substring(segment[4], end)
const value = encodeParam(key, params, decodeCharMap) ?? 'undefined'
const value =
(encode ? encodeParam(key, params, decodeCharMap) : params[key]) ??
'undefined'
joined += '/' + prefix + value + suffix
continue
}
Expand All @@ -335,7 +342,8 @@ export function interpolatePath({

usedParams[key] = valueRaw

const value = encodeParam(key, params, decodeCharMap) ?? ''
const value =
(encode ? encodeParam(key, params, decodeCharMap) : params[key]) ?? ''
joined += '/' + prefix + value + suffix
continue
}
Expand Down
14 changes: 6 additions & 8 deletions packages/router-core/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1184,7 +1184,7 @@ export class RouterCore<
pathname: decodePath(pathname),
searchStr,
search: replaceEqualDeep(previousLocation?.search, parsedSearch) as any,
hash: hash.split('#').reverse()[0] ?? '',
hash: last(hash.split('#')) ?? '',
state: replaceEqualDeep(previousLocation?.state, state),
}
}
Expand Down Expand Up @@ -1681,13 +1681,11 @@ export class RouterCore<
? // Use the original template path for interpolation
// This preserves the original parameter syntax including optional parameters
nextTo
: decodePath(
interpolatePath({
path: nextTo,
params: nextParams,
decodeCharMap: this.pathParamsDecodeCharMap,
}).interpolatedPath,
)
: interpolatePath({
path: nextTo,
params: nextParams,
encode: false,
}).interpolatedPath

// Resolve the next search
let nextSearch = fromSearch
Expand Down
Loading