[PR #463] [MERGED] fix: return route pattern from router.pathname, not resolved path #589

Closed
opened 2026-05-06 13:08:56 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/463
Author: @NathanDrake2406
Created: 3/11/2026
Status: Merged
Merged: 3/11/2026
Merged by: @james-elicx

Base: mainHead: fix/router-url-as-two-value


📝 Commits (8)

  • 715fd44 fix: stabilize instrumentation state and hydration E2E tests
  • ce20051 fix: honor the as parameter in router.push/replace
  • 3da95b4 fix: address PR review feedback
  • fad6f97 fix: remove pathname assertion that tests unimplemented behavior
  • 090b76c fix: return route pattern from router.pathname, not resolved path
  • 509e340 fix: set SSR pathname to route pattern to prevent hydration mismatch
  • a5bb971 Merge remote-tracking branch 'origin/main' into fix/router-url-as-two-value
  • eeb5fdc test: update entry-templates snapshots for pathname fix

📊 Changes

8 files changed (+16 additions, -12 deletions)

View changed files

📝 packages/vinext/src/build/static-export.ts (+2 -2)
📝 packages/vinext/src/entries/pages-server-entry.ts (+1 -1)
📝 packages/vinext/src/server/dev-server.ts (+1 -1)
📝 packages/vinext/src/shims/router.ts (+7 -2)
📝 tests/__snapshots__/entry-templates.test.ts.snap (+1 -1)
📝 tests/e2e/pages-router/dynamic-routes.spec.ts (+2 -2)
📝 tests/e2e/pages-router/navigation.spec.ts (+1 -2)
📝 tests/pages-router.test.ts (+1 -1)

📄 Description

Summary

  • router.pathname now returns the route pattern (e.g., /posts/[id]) instead of the resolved path (/posts/42), matching Next.js semantics
  • router.asPath continues to return the resolved browser URL as expected
  • Uses __NEXT_DATA__.page (which holds the route pattern from SSR and is updated on every client navigation) as the source of truth for pathname

Depends on #453 — this branch includes those commits. Merge #453 first, then this PR.

Closes #462

Test plan

  • Unit tests pass (652/652 in shims.test.ts)
  • Updated E2E assertion: router.pathname is /posts/[id] after as-based navigation
  • Updated E2E assertion: router.pathname is /posts/[id] on SSR page load
  • CI: all checks green

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/463 **Author:** [@NathanDrake2406](https://github.com/NathanDrake2406) **Created:** 3/11/2026 **Status:** ✅ Merged **Merged:** 3/11/2026 **Merged by:** [@james-elicx](https://github.com/james-elicx) **Base:** `main` ← **Head:** `fix/router-url-as-two-value` --- ### 📝 Commits (8) - [`715fd44`](https://github.com/cloudflare/vinext/commit/715fd4424bf22bc296a5d787c0307b41b45bcb38) fix: stabilize instrumentation state and hydration E2E tests - [`ce20051`](https://github.com/cloudflare/vinext/commit/ce200513747627e0a8cab9767c6f8898277f9088) fix: honor the `as` parameter in router.push/replace - [`3da95b4`](https://github.com/cloudflare/vinext/commit/3da95b448a389a029d4cc9b3b0262d2246dd5d27) fix: address PR review feedback - [`fad6f97`](https://github.com/cloudflare/vinext/commit/fad6f976244245db7a9033f5c8952afdc2e2fa1a) fix: remove pathname assertion that tests unimplemented behavior - [`090b76c`](https://github.com/cloudflare/vinext/commit/090b76cbc2f7fc92af822fbfcd6e7e7f8eb06d8a) fix: return route pattern from router.pathname, not resolved path - [`509e340`](https://github.com/cloudflare/vinext/commit/509e3401eddac4fb9cdc9f992e65c91bda1fe860) fix: set SSR pathname to route pattern to prevent hydration mismatch - [`a5bb971`](https://github.com/cloudflare/vinext/commit/a5bb971d2dd41334bcb0a6d7e5a0f5cceee8a2ab) Merge remote-tracking branch 'origin/main' into fix/router-url-as-two-value - [`eeb5fdc`](https://github.com/cloudflare/vinext/commit/eeb5fdca661320dccc57d5404897757f3a9a8715) test: update entry-templates snapshots for pathname fix ### 📊 Changes **8 files changed** (+16 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/build/static-export.ts` (+2 -2) 📝 `packages/vinext/src/entries/pages-server-entry.ts` (+1 -1) 📝 `packages/vinext/src/server/dev-server.ts` (+1 -1) 📝 `packages/vinext/src/shims/router.ts` (+7 -2) 📝 `tests/__snapshots__/entry-templates.test.ts.snap` (+1 -1) 📝 `tests/e2e/pages-router/dynamic-routes.spec.ts` (+2 -2) 📝 `tests/e2e/pages-router/navigation.spec.ts` (+1 -2) 📝 `tests/pages-router.test.ts` (+1 -1) </details> ### 📄 Description ## Summary - `router.pathname` now returns the route pattern (e.g., `/posts/[id]`) instead of the resolved path (`/posts/42`), matching Next.js semantics - `router.asPath` continues to return the resolved browser URL as expected - Uses `__NEXT_DATA__.page` (which holds the route pattern from SSR and is updated on every client navigation) as the source of truth for `pathname` **Depends on #453** — this branch includes those commits. Merge #453 first, then this PR. Closes #462 ## Test plan - [x] Unit tests pass (652/652 in `shims.test.ts`) - [x] Updated E2E assertion: `router.pathname` is `/posts/[id]` after `as`-based navigation - [x] Updated E2E assertion: `router.pathname` is `/posts/[id]` on SSR page load - [x] CI: all checks green --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 13:08:56 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#589
No description provided.