Skip to content

Commit b772d47

Browse files
fix: respect basename in loaders and actions redirects (#9418)
Co-authored-by: Mikaël ANZANO <[email protected]>
1 parent 892238b commit b772d47

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

contributors.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
- loun4
7373
- lqze
7474
- lukerSpringTree
75+
- manzano78
7576
- marc2332
7677
- markivancho
7778
- marvinruder

packages/router/router.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
convertRoutesToDataRoutes,
2828
invariant,
2929
isRouteErrorResponse,
30+
joinPaths,
3031
matchRoutes,
3132
} from "./utils";
3233

@@ -1515,6 +1516,17 @@ export function createRouter(init: RouterInit): Router {
15151516

15161517
let redirectHistoryAction =
15171518
replace === true ? HistoryAction.Replace : HistoryAction.Push;
1519+
let { basename = "/" } = init;
1520+
1521+
// If we're operating within a basename, prepend it to the pathname prior
1522+
// to handing off to history.
1523+
if (basename !== "/") {
1524+
navigation.location.pathname =
1525+
navigation.location.pathname === "/"
1526+
? basename
1527+
: joinPaths([basename, navigation.location.pathname]);
1528+
}
1529+
15181530
await startNavigation(redirectHistoryAction, navigation.location, {
15191531
overrideNavigation: navigation,
15201532
});

0 commit comments

Comments
 (0)