Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to <Link> to same page

Tags:

react-router

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.

like image 893
Mark L Avatar asked Mar 14 '16 02:03

Mark L


1 Answers

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

like image 59
Seagull Avatar answered Oct 20 '22 23:10

Seagull