vercel / vercel/next.js

URL Fragment is removed when navigating via next link to another page using a relative URL which results in a dynamic route

Open
#77,533 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Linking and Navigating
Dominant language
JavaScript
Stars
142k
Forks
32.4k
Avg merge
2d 14h
Merged PRs (30d)
351

Description

Link to the code that reproduces this issue

https://github.com/tklepzig/nextjs-link-with-fragment

To Reproduce
  1. npm i
  2. npm run dev
  3. Navigate to http://localhost:3000/42/subpage
  4. Click some of the links and check their desired target (e.g. the browser tooltip at the bottom of the page) with the URL which is routed to after clicking the link.
Current vs. Expected behavior

Expected: Several links are rendered on this page, all of them contain an URL fragment.
I expect clicking on all of these links I end up on a page with a fragment in the URL.

Observation: While some of them work, two links targeting another page by using a relative URL, which include a dynamic route don't have the fragment on the URL after routing. Additionally, for a href which does not contain a dynamic route the fragment is missing after routing as well if the link contains a slash before the hash char.

Provide environment information
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.1.0: Thu Oct 10 21:05:14 PDT 2024; root:xnu-11215.41.3~2/RELEASE_ARM64_T8103
  Available memory (MB): 16384
  Available CPU cores: 8
Binaries:
  Node: 20.8.1
  npm: 10.1.0
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 15.3.0-canary.23 // Latest available version is detected (15.3.0-canary.23).
  eslint-config-next: 15.3.0-canary.23
  react: 19.0.0
  react-dom: 19.0.0
  typescript: 5.8.2
Next.js Config:
  output: N/A
Which area(s) are affected? (Select all that apply)

Linking and Navigating

Which stage(s) are affected? (Select all that apply)

next dev (local), next start (local)

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproduction repository at https://github.com/tklepzig/nextjs-link-with-fragment. Run npm i and npm run dev, then visit /42/subpage and compare the relative links that target dynamic routes with the expected URL fragments. Done means the affected links preserve their fragments after client-side navigation in next dev and next start.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nextjs, react
Domain
frontend, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.