For this route:
<Route path="/about" component={AboutPage} />
## Link to anchor on same page
<!-- AboutPage.js -->
<a href='#someheader'>Jump to someheader</a>
Go to anchor someheader
on the current page (Not related to React-Router - this is simple HTML behavior). a element docs
## Link to anchor on another page (Tricky)
Jump to someheader
point on about
page.
This code will work (But you do not get the "power/features" of React-Router
):
<!-- HomePage.js -->
<!-- Simple href to anchor -->
<a href='about#someheader'>
Go to about page and jump to someheader
</a>
But when using the <Link>
component to navigate - the scroll to #hash will not work/scroll.
Related github issue: https://github.com/ReactTraining/react-router/issues/394
<!-- HomePage.js -->
<!-- anchor not working -->
<Link to='about#someheader'>
Go to About page without jumping to #someheader section
</Link >
How to solve this (True to Sep 20)?
- Use this package: https://www.npmjs.com/package/react-router-hash-link
- More ideas (Related/duplicate stackoverflow Q): Using anchor tags in react-router 4 // How to use normal anchor links with react-router