I'm converting some existing code to use React Router.
The code currently uses <a href="#" ...>
, which I am changing to <Link to=??>
.
My question is:
What should I use for the "to"
parameter? If I use to="#"
, the application routes to "/", which is not what I want.
It works if I use the current route name, but the whole idea of href="#"
is that the code doesn't have to know how it is accessed.
I am using React Router 2 with history=browserHistory.
For me this was the solution:
I used the npm module react-router-hash-link
. It is quite easy to use. Docs here
import { HashLink as Link } from 'react-router-hash-link';
<Link smooth to="/#services">Services</Link>
And wrap your <App>
component in <HashRouter>
from npm module react-router-dom
stackoverflow answer
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With