Skip to content

Track full url/as two-value navigation approach #462

@NathanDrake2406

Description

@NathanDrake2406

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

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions