diff --git a/src/presentation/routes/app-router.tsx b/src/presentation/routes/app-router.tsx index f0960f8d..f29122e6 100644 --- a/src/presentation/routes/app-router.tsx +++ b/src/presentation/routes/app-router.tsx @@ -21,6 +21,7 @@ import { getRoute, ROUTE_FEATURE_OWNER, ROUTE_REGISTRY, + ROUTE_RUNTIME_CONTRACT, } from "../../features/installed-feature-contracts.ts"; import { PLATFORM_ROUTE_REGISTRY, @@ -191,10 +192,15 @@ function CanonicalRouteRedirect({ useEffect(() => { if (input.routeId === "NOT_FOUND") return; const source = `${location.pathname}${location.search}`; - const target = buildRouteUrl(input.routeId, { + const canonical = buildRouteUrl(input.routeId, { params: input.params, search: input.search, }); + // D-16: a route that ignores its query leaves the query in the URL. + const target = + ROUTE_RUNTIME_CONTRACT[input.routeId].searchCodec === "none" + ? `${canonical}${location.search}` + : canonical; if (source === target) { guard.current.reset(); } else if (guard.current.allow(source, target)) { diff --git a/src/presentation/routes/platform-route-codecs.ts b/src/presentation/routes/platform-route-codecs.ts index 830f2e6f..103b3302 100644 --- a/src/presentation/routes/platform-route-codecs.ts +++ b/src/presentation/routes/platform-route-codecs.ts @@ -1,6 +1,8 @@ import { z } from "zod"; export const PLATFORM_ROUTE_CODECS = { - none: z.object({}).strict(), + // D-16: a route without input ignores unknown keys (`?utm_source=`, OAuth + // callback parameters) instead of calling the address invalid. + none: z.object({}), NotFoundSplat: z.object({ "*": z.string().optional() }).strict(), } as const; diff --git a/tests/component/router.test.tsx b/tests/component/router.test.tsx index 161343fa..2e36b123 100644 --- a/tests/component/router.test.tsx +++ b/tests/component/router.test.tsx @@ -148,9 +148,9 @@ describe("generic application router", () => { }, { surface: "invalid-route", - url: "/examples/ui?unexpected=1", - routeId: "EXAMPLES_UI", - title: "UI 구성요소 · Frontend Skeleton", + url: "/examples/reference-resources?limit=invalid", + routeId: "REFERENCE_RESOURCE_LIST", + title: "Reference resources · Frontend Skeleton", disableFeature: false, }, { @@ -200,6 +200,28 @@ describe("generic application router", () => { }, ); + it("ignores unknown query parameters on a platform route and keeps the URL", async () => { + // D-16: `/?utm_source=x` or an OAuth callback parameter is not an invalid + // address. The `none` codec drops it from the parsed input only. + window.history.pushState({}, "", "/examples/ui?utm_source=mail#top"); + const { container } = renderRouter(); + + expect( + await screen.findByRole( + "heading", + { name: "UI 구성요소", level: 1 }, + { timeout: 5000 }, + ), + ).toBeVisible(); + expect(container.querySelector('[data-surface="invalid-route"]')).toBeNull(); + await waitFor(() => + expect(document.title).toBe("UI 구성요소 · Frontend Skeleton"), + ); + expect(`${window.location.pathname}${window.location.search}`).toBe( + "/examples/ui?utm_source=mail", + ); + }); + it("focuses the route heading again when the lazy chunk is already cached", async () => { // §9.7. The first visit resolves the route module asynchronously, so the // router lifecycle and the page header commit separately. A later visit