Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Browser back button fails after navigation with URL anchor fragment #75072

Open
sgarrity opened this issue Jan 18, 2025 · 0 comments
Open

Browser back button fails after navigation with URL anchor fragment #75072

sgarrity opened this issue Jan 18, 2025 · 0 comments
Labels
create-next-app Related to our CLI tool for quickly starting a new Next.js application.

Comments

@sgarrity
Copy link

Link to the code that reproduces this issue

https://github.com/sgarrity/nextjs-anchor-link-testcase

To Reproduce

  1. Run the simple create-next-app example at https://github.com/sgarrity/nextjs-anchor-link-testcase
  2. Click on the "Anchor Example" link (or manually add a #example fragment at the end of the home page URL
  3. Click the "Go to Foobar" link (to /foobar)
  4. Click the browser Back button

Current vs. Expected behavior

Note how the URL shows the home URL with the fragment (http://localhost:3000/#anchor) but the Foobar (/foobar) page is still rendered in the browser, not the home page as intended.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.2.0: Fri Dec  6 19:01:59 PST 2024; root:xnu-11215.61.5~2/RELEASE_ARM64_T6000
  Available memory (MB): 32768
  Available CPU cores: 10
Binaries:
  Node: 20.11.1
  npm: 10.2.4
  Yarn: 1.22.22
  pnpm: 9.15.4
Relevant Packages:
  next: 15.1.5 // Latest available version is detected (15.1.5).
  eslint-config-next: N/A
  react: 19.0.0
  react-dom: 19.0.0
  typescript: N/A
Next.js Config:
  output: N/A

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

Not sure, create-next-app

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

next dev (local), next start (local)

Additional context

If I replace the example anchor fragment link with a next/link Link component instead of a stock tag, the browser back button works as intended. However, someone could always end up on a page with a URL fragment already there from an external link beyond your controle.

@github-actions github-actions bot added the create-next-app Related to our CLI tool for quickly starting a new Next.js application. label Jan 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
create-next-app Related to our CLI tool for quickly starting a new Next.js application.
Projects
None yet
Development

No branches or pull requests

1 participant