-
Notifications
You must be signed in to change notification settings - Fork 210
Description
Summary
Using an absolute URL with the same origin in <Link> causes a full page reload instead of client-side navigation.
I'm not sure if this is intended or a missed edge case.
Example:
<Link href="/path">works</Link>
<Link href="https://example.com/path">reloads page</Link>
When the domain matches the current origin, the router should treat it as an internal route and perform client-side navigation.
Expected behavior
Navigation should behave the same for both:
<Link href="/path" />
<Link href="https://example.com/path" />
If the URL origin matches window.location.origin, the router should treat it as an internal navigation and preserve layouts (SPA behavior).
This is how Next.js currently behaves.
Actual behavior
Using an absolute URL with the same domain causes a full page reload, which resets layouts and loses client state.
Steps to reproduce
- Create a Vinext app
- Add two routes (
/and/path) - Add the following links on
/:
<Link href="/path">Relative link</Link>
<Link href="https://example.com/path">Absolute same-origin link</Link>
- Click both links
Result:
- Relative link → client-side navigation
- Absolute link → full page reload
Environment
- Vinext: 0.0.24
- Node: 24.9.0
- Browser: Chrome
Possible cause
It seems the router only treats URLs starting with / as internal routes. Absolute URLs may not be normalized before routing.
Next.js normalizes same-origin URLs and converts them internally to relative paths before routing.
A similar approach might resolve this behavior.
Workaround
Use relative URLs for internal navigation:
<Link href="/path" />
However, this can be inconvenient or breaks current nextjs codebase when URLs are generated dynamically or include canonical/base URLs.