Skip to content
Merged
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
6 changes: 0 additions & 6 deletions packages/react-router/tests/router.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -706,12 +706,6 @@ describe('encoding/decoding: wildcard routes/params', () => {

await router.load()

expect(
router.state.location.href.endsWith(
'/framework/react/guide/file-based-routing%20tanstack',
),
).toBe(true)

expect(router.state.location.href).toBe(
'/framework/react/guide/file-based-routing%20tanstack',
)
Expand Down
27 changes: 26 additions & 1 deletion packages/router-core/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1252,9 +1252,34 @@ export class RouterCore<
previousLocation,
) => {
const parse = ({
pathname,
search,
hash,
href,
state,
}: HistoryLocation): ParsedLocation<FullSearchSchema<TRouteTree>> => {
// Fast path: no rewrite configured and pathname doesn't need encoding
// Characters that need encoding: space, high unicode, control chars
// eslint-disable-next-line no-control-regex
if (!this.rewrite && !/[ \x00-\x1f\x7f\u0080-\uffff]/.test(pathname)) {
const parsedSearch = this.options.parseSearch(search)
const searchStr = this.options.stringifySearch(parsedSearch)

return {
href: pathname + searchStr + hash,
publicHref: href,
pathname: decodePath(pathname),
external: false,
searchStr,
search: replaceEqualDeep(
previousLocation?.search,
parsedSearch,
) as any,
hash: decodePath(hash.slice(1)),
state: replaceEqualDeep(previousLocation?.state, state),
}
}

// Before we do any processing, we need to allow rewrites to modify the URL
// build up the full URL by combining the href from history with the router's origin
const fullUrl = new URL(href, this.origin)
Expand All @@ -1276,7 +1301,7 @@ export class RouterCore<
external: !!this.rewrite && url.origin !== this.origin,
searchStr,
search: replaceEqualDeep(previousLocation?.search, parsedSearch) as any,
hash: decodePath(url.hash.split('#').reverse()[0] ?? ''),
hash: decodePath(url.hash.slice(1)),
state: replaceEqualDeep(previousLocation?.state, state),
}
}
Expand Down
Loading