Skip to content

Commit 290d9e7

Browse files
authored
Fix pathless relative routing with a basename (#10433)
1 parent 666d962 commit 290d9e7

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@remix-run/router": patch
3+
---
4+
5+
Fix basename handling when navigating without a path

packages/router/__tests__/router-test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16220,5 +16220,29 @@ describe("a router", () => {
1622016220
expect(createPath(router.state.location)).toBe("/path");
1622116221
expect(router.state.matches[2].route.index).toBe(true);
1622216222
});
16223+
16224+
it("handles pathless relative routing when a basename is present", () => {
16225+
let router = createRouter({
16226+
routes: [{ path: "/path" }],
16227+
future: { v7_prependBasename: true },
16228+
history: createMemoryHistory({ initialEntries: ["/base/path"] }),
16229+
basename: "/base",
16230+
}).initialize();
16231+
16232+
expect(createPath(router.state.location)).toBe("/base/path");
16233+
expect(router.state.matches[0].route.path).toBe("/path");
16234+
16235+
router.navigate(".?a=1");
16236+
expect(createPath(router.state.location)).toBe("/base/path?a=1");
16237+
expect(router.state.matches[0].route.path).toBe("/path");
16238+
16239+
router.navigate("?b=2");
16240+
expect(createPath(router.state.location)).toBe("/base/path?b=2");
16241+
expect(router.state.matches[0].route.path).toBe("/path");
16242+
16243+
router.navigate("/path?c=3");
16244+
expect(createPath(router.state.location)).toBe("/base/path?c=3");
16245+
expect(router.state.matches[0].route.path).toBe("/path");
16246+
});
1622316247
});
1622416248
});

packages/router/router.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3094,7 +3094,7 @@ function normalizeTo(
30943094
let path = resolveTo(
30953095
to ? to : ".",
30963096
getPathContributingMatches(contextualMatches).map((m) => m.pathnameBase),
3097-
location.pathname,
3097+
stripBasename(location.pathname, basename) || location.pathname,
30983098
relative === "path"
30993099
);
31003100

0 commit comments

Comments
 (0)