I am new to react. I would like to implement react router as hash url. For Example I need a url #/list in react-router but by default react uses /list url. How can I implement hash url in react ?
1 Answer
You can make use of a HashURL, by making use of HashRouter instead of BrowserRouter for your router config
import { HashRouter, Route } from 'react-router-dom';
render() {
return <HashRouter>
<Route path="/" component={Home} />
</HashRouter>
}
In case you are using a react-router v3 or lower, you would specify hashHistory to Router
import { Router, Route, hashHistory } from 'react-router';
render() {
return <Router history={hashHistory}>
<Route path="/" component={Home} />
</Router>
}