@@ -148,7 +148,20 @@ describe("", () => {
);
const element = getByTestId("link");
- expect(element).toHaveAttribute("href", "/home");
+ expect(element).toHaveAttribute("href", "/app/home");
+ });
+
+ test("renders `href` with absolute links in nested routes", () => {
+ const { getByTestId } = render(
+
+
+
+
+
+ );
+
+ const element = getByTestId("link");
+ expect(element.getAttribute("href")).toBe("/app/home");
});
test("supports history state", () => {
@@ -180,9 +193,9 @@ describe("", () => {
>
);
- expect(getByTestId("root")).toHaveAttribute("href", "#/");
- expect(getByTestId("home")).toHaveAttribute("href", "#/home");
- expect(getByTestId("absolute")).toHaveAttribute("href", "#/home");
+ expect(getByTestId("root").getAttribute("href")).toBe("#/");
+ expect(getByTestId("home").getAttribute("href")).toBe("#/home");
+ expect(getByTestId("absolute").getAttribute("href")).toBe("#/app/home");
});
});
@@ -403,4 +416,47 @@ describe(" with `asChild` prop", () => {
expect(link).toHaveAttribute("href", undefined);
expect(link).toHaveTextContent("Click Me");
});
+
+ test("issue #558: ~ paths respect base in nested routes", () => {
+ const memLoc = memoryLocation({
+ path: "/app/schedule/2026-02-11",
+ });
+
+ const ScheduleDetail = () => (
+
+
Schedule Detail
+
+ Back to Overview
+
+
+ );
+
+ const { getByTestId } = render(
+
+
+
+
+
+ );
+
+ const backLink = getByTestId("back-link");
+ expect(backLink.getAttribute("href")).toBe("/app/schedule");
+
+ fireEvent.click(backLink);
+
+ // The navigate function will trigger, and we can verify by rendering a component
+ // that uses the location hook
+ const LocationDisplay = () => {
+ const [location] = memLoc.hook();
+ return {location}
;
+ };
+
+ const { getByTestId: getByTestId2 } = render(
+
+
+
+ );
+
+ expect(getByTestId2("location").textContent).toBe("/app/schedule");
+ });
});
diff --git a/packages/wouter/test/redirect.test.tsx b/packages/wouter/test/redirect.test.tsx
index b607ef9..d96dc72 100644
--- a/packages/wouter/test/redirect.test.tsx
+++ b/packages/wouter/test/redirect.test.tsx
@@ -31,7 +31,7 @@ test("supports `base` routers with absolute path", () => {
);
- expect(location.pathname).toBe("/absolute");
+ expect(location.pathname).toBe("/app/absolute");
});
test("supports replace navigation", () => {
diff --git a/packages/wouter/test/url-pattern.test.tsx b/packages/wouter/test/url-pattern.test.tsx
index 26c83e9..81850a2 100644
--- a/packages/wouter/test/url-pattern.test.tsx
+++ b/packages/wouter/test/url-pattern.test.tsx
@@ -175,7 +175,7 @@ test("Switch, inherited params and links work with nested URLPattern routes", ()
);
const [next, outside] = Array.from(container.querySelectorAll("a"));
expect(next.getAttribute("href")).toBe("/app/users/42/posts/8");
- expect(outside.getAttribute("href")).toBe("/outside");
+ expect(outside.getAttribute("href")).toBe("/app/outside");
fireEvent.click(next);
expect(container.querySelector("span")?.textContent).toBe(
"42:8:/app/users/42:/posts/8"