Skip to content

Commit e755316

Browse files
fix: do not pre-decodeURI before passing to createMemoryHistory (#4893)
fixes #4514
1 parent 0a3bb24 commit e755316

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

packages/react-router/src/useBlocker.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export function useBlocker(
176176
function getLocation(
177177
location: HistoryLocation,
178178
): AnyShouldBlockFnLocation {
179-
const parsedLocation = router.parseLocation(undefined, location)
179+
const parsedLocation = router.parseLocation(location)
180180
const matchedRoutes = router.getMatchedRoutes(
181181
parsedLocation.pathname,
182182
undefined,

packages/router-core/src/router.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -614,8 +614,8 @@ export type InvalidateFn<TRouter extends AnyRouter> = (opts?: {
614614
}) => Promise<void>
615615

616616
export type ParseLocationFn<TRouteTree extends AnyRoute> = (
617+
locationToParse: HistoryLocation,
617618
previousLocation?: ParsedLocation<FullSearchSchema<TRouteTree>>,
618-
locationToParse?: HistoryLocation,
619619
) => ParsedLocation<FullSearchSchema<TRouteTree>>
620620

621621
export type GetMatchRoutesFn = (
@@ -901,7 +901,7 @@ export class RouterCore<
901901
initialEntries: [this.basepath || '/'],
902902
})
903903
: createBrowserHistory()) as TRouterHistory)
904-
this.latestLocation = this.parseLocation()
904+
this.updateLatestLocation()
905905
}
906906

907907
if (this.options.routeTree !== this.routeTree) {
@@ -939,6 +939,13 @@ export class RouterCore<
939939
return this.__store.state
940940
}
941941

942+
updateLatestLocation = () => {
943+
this.latestLocation = this.parseLocation(
944+
this.history.location,
945+
this.latestLocation,
946+
)
947+
}
948+
942949
buildRouteTree = () => {
943950
const { routesById, routesByPath, flatRoutes } = processRouteTree({
944951
routeTree: this.routeTree,
@@ -985,8 +992,8 @@ export class RouterCore<
985992
}
986993

987994
parseLocation: ParseLocationFn<TRouteTree> = (
988-
previousLocation,
989995
locationToParse,
996+
previousLocation,
990997
) => {
991998
const parse = ({
992999
pathname,
@@ -1007,7 +1014,7 @@ export class RouterCore<
10071014
}
10081015
}
10091016

1010-
const location = parse(locationToParse ?? this.history.location)
1017+
const location = parse(locationToParse)
10111018

10121019
const { __tempLocation, __tempKey } = location.state
10131020

@@ -1805,7 +1812,7 @@ export class RouterCore<
18051812
beforeLoad = () => {
18061813
// Cancel any pending matches
18071814
this.cancelMatches()
1808-
this.latestLocation = this.parseLocation(this.latestLocation)
1815+
this.updateLatestLocation()
18091816

18101817
if (this.isServer) {
18111818
// for SPAs on the initial load, this is handled by the Transitioner

packages/solid-router/src/useBlocker.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export function useBlocker(
185185
function getLocation(
186186
location: HistoryLocation,
187187
): AnyShouldBlockFnLocation {
188-
const parsedLocation = router.parseLocation(undefined, location)
188+
const parsedLocation = router.parseLocation(location)
189189
const matchedRoutes = router.getMatchedRoutes(
190190
parsedLocation.pathname,
191191
undefined,

packages/start-server-core/src/createStartHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export function createStartHandler<TRouter extends AnyRouter>({
111111
}
112112

113113
const url = new URL(request.url)
114-
const href = decodeURIComponent(url.href.replace(url.origin, ''))
114+
const href = url.href.replace(url.origin, '')
115115

116116
const APP_BASE = process.env.TSS_APP_BASE || '/'
117117

0 commit comments

Comments
 (0)