rafgraph / react-router-hash-link

Hash link scroll functionality for React Router
https://react-router-hash-link.rafgraph.dev
MIT License
732 stars 62 forks source link

Update hash as the user scrolls through a page #79

Closed mfilteau closed 3 years ago

mfilteau commented 3 years ago

Consider a navbar where links can go to sections on a page or to a different page. When a user scrolls through a page and a new section become visible, it would be great if the corresponding section's hash gets updated on the browser's location and the corresponding navbar link becomes active.

The react-scroll library supports this feature but unfortunately only handles links within the current page.

rafgraph commented 3 years ago

HI, thanks for the suggestion, but unfortunately that is out of scope for this library. You can implement the detection yourself (using something like Intersection Observer), and then use history.push(...) to update the hash in the url.