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

Handle "active" class when <NavHashLink to="#" /> #69

Closed saramorillon closed 3 years ago

saramorillon commented 3 years ago

When having a NavHashLink linking to the top of the page using "#" anchor, the active class is not set.

This PR aims at fixing this issue.

rafgraph commented 3 years ago

So this is caused by a bug in React Router that strips empty # hash fragments. https://github.com/ReactTraining/react-router/issues/7649

I'm hoping they'll consider reopening the issue so this work around is not necessary.

saramorillon commented 3 years ago

Ok, thank you for the information. Hope they'll fix the issue.

rafgraph commented 3 years ago

Closing because this is a React Router issue. As a workaround you can use #top instead of #.