mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[GH-ISSUE #335] Unexpected next/link Behavior: <Link> with same-origin absolute URL triggers full page reload #78
Labels
No labels
enhancement
enhancement
good first issue
help wanted
nextjs-tracking
nextjs-tracking
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vinext#78
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @sindhukhrisna on GitHub (Mar 7, 2026).
Original GitHub issue: https://github.com/cloudflare/vinext/issues/335
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:
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:
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
/and/path)/:Result:
Environment
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:
However, this can be inconvenient or breaks current nextjs codebase when URLs are generated dynamically or include canonical/base URLs.
@Divkix commented on GitHub (Mar 8, 2026):
Fix submitted in #336.
Changes:
toSameOriginPath()utility that comparesnew URL(href).originagainstwindow.location.originand extracts the local path when they matchlink.tsx(handleClick + prefetch),navigation.ts(App RouternavigateImpl), androuter.ts(Pages Routerpush/replacein both hook and singleton)<Link>with absolute URLs@sindhukhrisna commented on GitHub (Mar 8, 2026):
Thank you for this very fast fix