Link to the code that reproduces this issue
https://github.com/timonrey/next-link-hash-repro
To Reproduce
To Reproduce
- Clone the repro repository.
- Run
npm install.
- Run
npm run build.
- Run
npm run start.
- Open
http://localhost:3100/#section-a.
- Click
Next hash link to section B.
- Open
http://localhost:3100/#section-a again.
- Click
Go to other page with Next pathname string.
- On
/other, click Back home with Next pathname string.
Current vs. Expected behavior
Current vs. Expected behavior
Current behavior in local production (next build && next start):
- clicking the
next/link hash link from /#section-a produces /#section-a#section-b
- navigating away from
/#section-a with next/link and then returning with a pathname-only next/link restores the stale fragment and lands on /#section-a
Expected behavior:
- clicking the same-page hash link should replace the fragment and land on
/#section-b
- pathname-only navigation back to
/ should land on / and should not silently restore the old fragment
Control behavior in the same repro:
- native hash links correctly land on
/#section-b
- native cross-page navigation correctly returns to
/
Provide environment information
### Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: macOS
Available memory (MB): unknown
Available CPU cores: unknown
Binaries:
Node: 22.14.0
npm: 10.9.2
Yarn: not used in repro
Relevant Packages:
next: 16.2.6
react: 19.2.4
react-dom: 19.2.4
Browser:
Chromium
Which area(s) are affected? (Select all that apply)
Linking and Navigating, Route Handlers
Which stage(s) are affected? (Select all that apply)
next build (local), next start (local)
Additional context
Additional context
- The repro uses the App Router.
- This issue happens on all browsers
- The same flows did not reproduce in
next dev in this minimal app.
- The repro includes a small URL debugger that logs
pushState, replaceState, hashchange, and popstate.
- In the duplicate-fragment case, the debugger logs
pushState(/#section-a#section-b) even though the clicked link is href="#section-b".
Link to the code that reproduces this issue
https://github.com/timonrey/next-link-hash-repro
To Reproduce
To Reproduce
npm install.npm run build.npm run start.http://localhost:3100/#section-a.Next hash link to section B.http://localhost:3100/#section-aagain.Go to other page with Next pathname string./other, clickBack home with Next pathname string.Current vs. Expected behavior
Current vs. Expected behavior
Current behavior in local production (
next build && next start):next/linkhash link from/#section-aproduces/#section-a#section-b/#section-awithnext/linkand then returning with a pathname-onlynext/linkrestores the stale fragment and lands on/#section-aExpected behavior:
/#section-b/should land on/and should not silently restore the old fragmentControl behavior in the same repro:
/#section-b/Provide environment information
Which area(s) are affected? (Select all that apply)
Linking and Navigating, Route Handlers
Which stage(s) are affected? (Select all that apply)
next build (local), next start (local)
Additional context
Additional context
next devin this minimal app.pushState,replaceState,hashchange, andpopstate.pushState(/#section-a#section-b)even though the clicked link ishref="#section-b".