Support Automatic Scrolling to Hashed Fragments #13347
FarhanXTanvir
started this conversation in
Proposals
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In previous versions of React Router, when navigating to a URL with a hash fragment (e.g., /home#contact), the browser would automatically scroll to the element with the corresponding id. However, in React Router v7, while the navigation updates the URL, the expected scrolling behavior does not occur.
Example Case:
When the user clicks "Contact Us", they expect:
To be navigated to "/home". ✅ (Works as expected)
The page to scroll to the element with id="contact". ❌ (Does not happen in React Router v7)
Expected Behavior:
React Router should automatically detect hash fragments and scroll to the corresponding id, restoring the behavior expected in native browser navigation.
Proposed Solution:
Introduce built-in support for hash-based scrolling in or as a global option in
<BrowserRouter>
.Would love to hear the team's thoughts on whether this could be included in an update.
Beta Was this translation helpful? Give feedback.
All reactions