-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Anchor Links / Hash in URL is ignored on initial page load #21120
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. |
@danspratling: I let this thread open for now to get hopefully an anweser. |
Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here. Thanks for being a part of the Gatsby community! 💪💜 |
Yep this has bitten me too! |
@danspratling you'll want to also update the // Fix scrolling for ids starting with numbers
// https://stackoverflow.com/a/20306237/1268612
const hash = location.hash.replace(/^#(\d)/, '#\\3$1'); |
Fixed in latest! |
…ker da det ga litt rar oppførsel og ikke er anbefalt av gatsby måtte implementere litt custom greier da dette ikke ser ut til å virke ut av boksen med gatsby gatsbyjs/gatsby#21120 https://codingcat.dev/blog/anchor-links-from-sanity-in-gatsby/#sanityio https://stackoverflow.com/questions/24665602/scrollintoview-scrolls-just-too-far trodde egentlig denne PR'en skulle fikse det, men ser ikke at det funker..? gatsbyjs/gatsby#24306
It looks like this issue is presenting itself again in Gatsby v5 |
Still showing this issue in 5.8.1 danspratling's fix is still working
|
Description
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(R) Core(TM) 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
The text was updated successfully, but these errors were encountered: