question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Jump link anchors dont work

See original GitHub issue

Bug report

Describe the bug

When clicking an anchor tag in a different page with a jump to id tag, it raises an error and doesnt go.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

<a className='nav-link' href='https://github.com/zeit/next.js/#documentation' > Docs </a>

Expected behavior

should redirect to github and scroll to documentation tag

Screenshots

Screenshot 2020-03-16 at 15 13 05

System information

  • Browser (if applies): Chrome
  • Nextjs version: 9.1.6

Additional context

I’ve tried this in another project without nextjs and it works fine i also tried in a random place like

https://jsfiddle.net/uqxck4jv/

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:12
  • Comments:38 (1 by maintainers)

github_iconTop GitHub Comments

19reactions
Seybocommented, Dec 27, 2020

Here is how i adapted the above because it doesn’t work on mobile for me:

  React.useEffect(() => {
    const path = window.location.hash
    if (path && path.includes("#")) {
      setTimeout(() => {
        const id = path.replace("#", "")
        const el = window.document.getElementById(id)
        const r = el.getBoundingClientRect()
        window.top.scroll({
          top: pageYOffset + r.top,
          behavior: "smooth",
        })
      }, 600)
    }
18reactions
jasdeepsinghcommented, Sep 21, 2021

Have this exact same issue.

Why is this not a priority for the Nextjs team? This is breaking a pretty common web pattern for any sites built on top of Nextjs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTML Anchor Jump Doesn't Work - Stack Overflow
when i setup a link to jump to a certain div it doesn't work. For example when i say <a href="#Section1>Section 1</a> and...
Read more >
Anchor Links/Jump Links – Just Going Too Far | WordPress.org
Hi, I used the block editor feature to create an anchor link to jump to a specific headline, and it works, but the...
Read more >
Anchor Links to another page not working in Chrome
On that page I have a link to jump to the second section. Within that page the link works fine. If I use...
Read more >
Anchor link to different page not working (jumping back to top ...
For some reason every time I do a fresh reload of the page, it does go to the anchor on load but only...
Read more >
How to Add an Anchor Link to Jump to a Specific Part of a Page
An anchor link is a link, which allows the users to flow through a website page. It helps to scroll and skim-read easily....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found