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

How to control isActive property #72

Closed tomcanac closed 3 years ago

tomcanac commented 3 years ago

Hi,

I managed to use window.history.replaceState to push anchors to the URL at scroll on my app page. It works well, but my URL update doesn't change the current isActive anchor button.

Any help on how to sync the isActive property with self updated URL hash would be amazing, thanks for the library, it helps a lot!

rafgraph commented 3 years ago

Try using Rect Router's replaceState function, not the one on the window, otherwise React Router doesn't know the url has changed. If you provide an isActive prop it is passed through to React Router's <NavLink>, so see the React Router docs (you should be able to pass in a boolean).

tomcanac commented 3 years ago

good, thanks for the information! Indeed it does work with importing the history object from my main app.

Thanks for the help!