Skip to content

[NEXT-658] Nextjs 13 Link not scrolling to anchor element #44295

@vladgardus

Description

@vladgardus

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 10 Pro
Binaries:
  Node: 16.13.1
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant packages:
  next: 13.0.6
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

No response

Link to the code that reproduces this issue

no github link

To Reproduce

  • Add Link with href={{ pathname: /, hash: "home" }}
  • add div with id="home"
  • clicking on link will not scroll to div

Describe the Bug

Working on a next 13 app using the experimental flag.

Created a header that has 3 next/link elements and the purpose of those 3 links is to set a hash on the URL and scroll to that anchor element.

The issue is that clicking on those links change the URL but does not scroll to the anchor element, but the strange thing is that by manually changing the hash in the URL does in fact trigger that scroll to the anchor element.

Expected Behavior

Links that add hashes to URL should scroll to the anchor element.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

NEXT-658

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue was opened via the bug report template.linear: nextConfirmed issue that is tracked by the Next.js team.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions