Anchor Links / Hash in URL is ignored on initial page load
See original GitHub issueDescription
I am having a SPA built with gatsby. I am using <a href="/#sectionX">section x</a>
links for navigation in the header. This is working just fine.
Unfortunately, reloading the page (having the anchor link in the URL) does not scroll to the expected section but stays unscrolled at the top of the page.
Steps to reproduce
Take any gatsby starter, add anchor link, reload page.
Expected result
Page should automatically scroll to desired section as provided in the URL on initial page load.
Actual result
Hash is ignored and page does not scroll
Environment
System: OS: Windows 10 10.0.17763 CPU: (8) x64 Intel® Core™ i7-4770 CPU @ 3.40GHz Binaries: Node: 12.13.0 - C:\Program Files\nodejs\node.EXE npm: 6.12.0 - C:\Program Files\nodejs\npm.CMD Languages: Python: 2.7.17 Browsers: Edge: 44.17763.831.0
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:6 (3 by maintainers)
Top Results From Across the Web
567218 - anchor ignored on page load(but it works if clicked ...
Now put cursor on the end of the URL/HASH again and press ENTER. The browser now sees no change in the HASH and...
Read more >Reloading a page; anchor link is being ignored and previous ...
I have a form that does an ajax call, and on success, reloads the (same) page and jumps to the submitted data toward...
Read more >anchors not working correctly on web pages - Google Chrome ...
I have links to a page that go to a specific anchor (using the <a name> for the specific section and # after...
Read more >Making the anchor links work in SPA applications
Making the anchor links work in SPA applications. A solution for react-router and other history based routing #hash navigation. The problem is simple:...
Read more >How to load a #hash fragment to an anchor name in react ...
This behavior occurs for several reasons, one reason is because the anchor name offset is executed after the page loads the first DOM,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Looks like gatsby takes control of the scroll position but you can use the gatsby-browser.js file to add a function to re-enable anchor links.
I’m not sure if the default browser behaviour for anchor links being disabled is intentional or not though. Would be worth getting some feedback from someone on the internal team.
Fixed in latest!