-
Notifications
You must be signed in to change notification settings - Fork 220
Description
Context
In Next.js, router.push(url, as) keeps url and as as separate values throughout the navigation lifecycle:
urldetermines which page module to load and which data to fetchasis the cosmetic URL shown in the browser bar- Both are stored in
history.statefor 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.pathnamenow correctly returns the route pattern (/posts/[id]) instead of the resolved path (/posts/42) — fixed in fix: return route pattern from router.pathname, not resolved path #463asparameter support inrouter.push/replace— fixed in fix: honor theasparameter in router.push/replace #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:
- Store both
urlandasinhistory.state - On popstate, use the stored
urlfor data fetching instead ofwindow.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.