Skip to content

Commit

Permalink
Fix pathless relative routing with a basename (#10433)
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 authored May 2, 2023
1 parent 666d962 commit 290d9e7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/empty-path-basename-navigation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/router": patch
---

Fix basename handling when navigating without a path
24 changes: 24 additions & 0 deletions packages/router/__tests__/router-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16220,5 +16220,29 @@ describe("a router", () => {
expect(createPath(router.state.location)).toBe("/path");
expect(router.state.matches[2].route.index).toBe(true);
});

it("handles pathless relative routing when a basename is present", () => {
let router = createRouter({
routes: [{ path: "/path" }],
future: { v7_prependBasename: true },
history: createMemoryHistory({ initialEntries: ["/base/path"] }),
basename: "/base",
}).initialize();

expect(createPath(router.state.location)).toBe("/base/path");
expect(router.state.matches[0].route.path).toBe("/path");

router.navigate(".?a=1");
expect(createPath(router.state.location)).toBe("/base/path?a=1");
expect(router.state.matches[0].route.path).toBe("/path");

router.navigate("?b=2");
expect(createPath(router.state.location)).toBe("/base/path?b=2");
expect(router.state.matches[0].route.path).toBe("/path");

router.navigate("/path?c=3");
expect(createPath(router.state.location)).toBe("/base/path?c=3");
expect(router.state.matches[0].route.path).toBe("/path");
});
});
});
2 changes: 1 addition & 1 deletion packages/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3094,7 +3094,7 @@ function normalizeTo(
let path = resolveTo(
to ? to : ".",
getPathContributingMatches(contextualMatches).map((m) => m.pathnameBase),
location.pathname,
stripBasename(location.pathname, basename) || location.pathname,
relative === "path"
);

Expand Down

0 comments on commit 290d9e7

Please sign in to comment.