[GH-ISSUE #462] Track full url/as two-value navigation approach #105

Closed
opened 2026-05-06 12:37:14 +02:00 by BreizhHardware · 0 comments

Originally created by @NathanDrake2406 on GitHub (Mar 11, 2026).
Original GitHub issue: https://github.com/cloudflare/vinext/issues/462

Context

In Next.js, router.push(url, as) keeps url and as as separate values throughout the navigation lifecycle:

  • url determines which page module to load and which data to fetch
  • as is the cosmetic URL shown in the browser bar
  • Both are stored in history.state for back/forward restoration

vinext currently collapses them into a single value in resolveNavigationTarget() — when as is provided, url is discarded entirely. The result is used for both history.pushState and navigateClient().

What's been fixed

  • router.pathname now correctly returns the route pattern (/posts/[id]) instead of the resolved path (/posts/42) — fixed in #463
  • as parameter support in router.push/replace — fixed in #453

What remains

Purely decorative as values that don't map to a real server route would cause navigateClient() to fetch the wrong page or 404. On popstate (back/forward), we only have the as value from the URL bar — Next.js retrieves the stored url from history.state for data fetching.

To fully match Next.js, we'd need to:

  1. Store both url and as in history.state
  2. On popstate, use the stored url for data fetching instead of window.location.pathname

When to implement

This was largely replaced by rewrites after Next.js 9.5.3, so the purely-decorative pattern is rare. Implement if someone reports a real-world use case that breaks.

Ref: PR #453 review discussion.

Originally created by @NathanDrake2406 on GitHub (Mar 11, 2026). Original GitHub issue: https://github.com/cloudflare/vinext/issues/462 ## Context In Next.js, `router.push(url, as)` keeps `url` and `as` as **separate values** throughout the navigation lifecycle: - `url` determines which page module to load and which data to fetch - `as` is the cosmetic URL shown in the browser bar - Both are stored in `history.state` for back/forward restoration vinext currently collapses them into a single value in `resolveNavigationTarget()` — when `as` is provided, `url` is discarded entirely. The result is used for both `history.pushState` and `navigateClient()`. ## What's been fixed - **`router.pathname`** now correctly returns the route pattern (`/posts/[id]`) instead of the resolved path (`/posts/42`) — fixed in #463 - **`as` parameter support** in `router.push`/`replace` — fixed in #453 ## What remains Purely decorative `as` values that don't map to a real server route would cause `navigateClient()` to fetch the wrong page or 404. On popstate (back/forward), we only have the `as` value from the URL bar — Next.js retrieves the stored `url` from `history.state` for data fetching. To fully match Next.js, we'd need to: 1. Store both `url` and `as` in `history.state` 2. On popstate, use the stored `url` for data fetching instead of `window.location.pathname` ## When to implement This was largely replaced by `rewrites` after Next.js 9.5.3, so the purely-decorative pattern is rare. Implement if someone reports a real-world use case that breaks. Ref: PR #453 review discussion.
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#105
No description provided.