diff --git a/tests/docs-site.spec.ts b/tests/docs-site.spec.ts index 6c50e37..cbf2322 100644 --- a/tests/docs-site.spec.ts +++ b/tests/docs-site.spec.ts @@ -394,6 +394,28 @@ test("bridges legacy hash routes to clean URLs", async ({ page }) => { await page.goto("/#/api-reference"); await expect(page).toHaveURL(/\/api-reference(?:\/calls)?$/); + + for (const hash of [ + "api-reference", + "tag/Calls", + "/tag/Calls", + "description/auth", + "/description/auth", + "models", + "/models", + ]) { + await page.goto(`/#${hash}`); + await expect(page).toHaveURL(/\/api-reference(?:\/calls)?$/); + } + + await page.goto("/#calls?section=idempotency"); + await expect(page).toHaveURL(/\/calls#idempotency$/); + + await page.goto("/"); + await expect(page).toHaveURL(/\/quickstart$/); + + await page.goto("/#not-a-docs-route"); + await expect(page).toHaveURL(/\/#not-a-docs-route$/); }); test("renders every migrated guide from its file route", async ({ page }) => { diff --git a/zudoku.config.tsx b/zudoku.config.tsx index 050d810..0b547f9 100644 --- a/zudoku.config.tsx +++ b/zudoku.config.tsx @@ -7,7 +7,8 @@ const legacyHashRedirect = ` (() => { if (window.location.pathname !== "/") return; - const [route, query = ""] = window.location.hash.slice(1).split("?", 2); + const [rawRoute, query = ""] = window.location.hash.slice(1).split("?", 2); + const route = rawRoute.startsWith("/") || rawRoute === "" ? rawRoute : \`/\${rawRoute}\`; const guideRoutes = new Set([ "/quickstart", "/authentication", @@ -31,15 +32,17 @@ const legacyHashRedirect = ` if ( route === "/api-reference" || route.startsWith("/api-1/") || - route.startsWith("tag/") || - route.startsWith("description/") || - route === "models" + route.startsWith("/tag/") || + route.startsWith("/description/") || + route === "/models" ) { window.location.replace("/api-reference"); return; } - window.location.replace("/quickstart"); + if (rawRoute === "") { + window.location.replace("/quickstart"); + } })(); `;