diff --git a/packages/vinext/src/build/static-export.ts b/packages/vinext/src/build/static-export.ts index 1163898d..79de1cec 100644 --- a/packages/vinext/src/build/static-export.ts +++ b/packages/vinext/src/build/static-export.ts @@ -18,7 +18,7 @@ * - Dynamic routes without generateStaticParams → build error */ import type { ViteDevServer } from "vite"; -import type { Route } from "../routing/pages-router.js"; +import { patternToNextFormat, type Route } from "../routing/pages-router.js"; import type { AppRoute } from "../routing/app-router.js"; import type { ResolvedNextConfig } from "../config/next-config.js"; import { safeJsonStringify } from "../server/html.js"; @@ -277,7 +277,7 @@ async function renderStaticPage(options: RenderStaticPageOptions): Promise = {}; // Include dynamic route params from __NEXT_DATA__ (e.g., { id: "42" } from /posts/[id]). // Only include keys that are part of the route pattern (not stale query params). @@ -302,7 +306,8 @@ function getPathnameAndQuery(): { addQueryParam(searchQuery, key, value); } const query = { ...searchQuery, ...routeQuery }; - const asPath = pathname + window.location.search + window.location.hash; + // asPath uses the resolved browser path, not the route pattern + const asPath = resolvedPath + window.location.search + window.location.hash; return { pathname, query, asPath }; } diff --git a/tests/__snapshots__/entry-templates.test.ts.snap b/tests/__snapshots__/entry-templates.test.ts.snap index 40ce67c8..7b814337 100644 --- a/tests/__snapshots__/entry-templates.test.ts.snap +++ b/tests/__snapshots__/entry-templates.test.ts.snap @@ -18128,7 +18128,7 @@ async function _renderPage(request, url, manifest) { try { if (typeof setSSRContext === "function") { setSSRContext({ - pathname: routeUrl.split("?")[0], + pathname: patternToNextFormat(route.pattern), query: { ...params, ...parseQuery(routeUrl) }, asPath: routeUrl, locale: locale, diff --git a/tests/e2e/pages-router/dynamic-routes.spec.ts b/tests/e2e/pages-router/dynamic-routes.spec.ts index 35c3023c..a1d1062d 100644 --- a/tests/e2e/pages-router/dynamic-routes.spec.ts +++ b/tests/e2e/pages-router/dynamic-routes.spec.ts @@ -6,8 +6,8 @@ test.describe("Dynamic routes with getServerSideProps", () => { test("renders post page with dynamic id from GSSP", async ({ page }) => { await page.goto(`${BASE}/posts/123`); await expect(page.locator('[data-testid="post-title"]')).toHaveText("Post: 123"); - // vinext returns the resolved pathname (not the route pattern) - await expect(page.locator('[data-testid="pathname"]')).toHaveText("Pathname: /posts/123"); + // router.pathname returns the route pattern, not the resolved path + await expect(page.locator('[data-testid="pathname"]')).toHaveText("Pathname: /posts/[id]"); await expect(page.locator('[data-testid="query"]')).toHaveText("Query ID: 123"); }); diff --git a/tests/e2e/pages-router/navigation.spec.ts b/tests/e2e/pages-router/navigation.spec.ts index d04802fd..7bd1cb91 100644 --- a/tests/e2e/pages-router/navigation.spec.ts +++ b/tests/e2e/pages-router/navigation.spec.ts @@ -75,8 +75,7 @@ test.describe("Client-side navigation", () => { await expect(page.locator('[data-testid="as-path"]')).toHaveText( "As Path: /posts/42?from=hook", ); - // TODO(#462): after implementing two-value url/as navigation, assert that - // router.pathname stays as the route pattern (/posts/[id]) not the resolved path. + await expect(page.locator('[data-testid="pathname"]')).toHaveText("Pathname: /posts/[id]"); expect(page.url()).toBe(`${BASE}/posts/42?from=hook`); }); diff --git a/tests/pages-router.test.ts b/tests/pages-router.test.ts index c3949321..d448cd1f 100644 --- a/tests/pages-router.test.ts +++ b/tests/pages-router.test.ts @@ -105,7 +105,7 @@ describe("Pages Router integration", () => { expect(html).toMatch(/Post:\s*()?\s*42/); expect(html).toContain("post-title"); // Router should have correct pathname and query during SSR - expect(html).toMatch(/Pathname:\s*()?\s*\/posts\/42/); + expect(html).toMatch(/Pathname:\s*()?\s*\/posts\/\[id\]/); expect(html).toMatch(/Query ID:\s*()?\s*42/); });