diff --git a/src/runtime/client/partials.ts b/src/runtime/client/partials.ts
index cd2e6cc2..6537d9a3 100644
--- a/src/runtime/client/partials.ts
+++ b/src/runtime/client/partials.ts
@@ -288,6 +288,7 @@ async function fetchPartials(
init: RequestInit = {},
) {
init.redirect = "follow";
+ partialUrl = new URL(partialUrl);
partialUrl.searchParams.set(PARTIAL_SEARCH_PARAM, "true");
const res = await fetch(partialUrl, init);
diff --git a/tests/partials_test.tsx b/tests/partials_test.tsx
index 8f480e43..2de6b95d 100644
--- a/tests/partials_test.tsx
+++ b/tests/partials_test.tsx
@@ -2274,3 +2274,46 @@ Deno.test({
});
},
});
+
+Deno.test({
+ name: "partials - backwards navigation should keep URLs",
+ fn: async () => {
+ const app = testApp()
+ .get("/other", (ctx) => {
+ return ctx.render(
+
+
+ other
+
+
+ ,
+ );
+ })
+ .get("/", (ctx) => {
+ return ctx.render(
+
+
+ ,
+ );
+ });
+
+ await withBrowserApp(app, async (page, address) => {
+ await page.goto(address, { waitUntil: "load" });
+ await page.locator(".ready").wait();
+ await page.locator("a").click();
+ await page.locator(".done").wait();
+
+ await page.evaluate(() => window.history.go(-1));
+ await page.locator(".init").wait();
+ const rawUrl = await page.evaluate(() => window.location.href);
+ const url = new URL(rawUrl);
+ expect(`${url.pathname}${url.search}`).toEqual("/");
+ });
+ },
+});