Karan
Karan

Reputation: 1118

Remove # from url in react

I am creating a project using reactjs.In my project i want to remove # from the url. Currently i am using the react-router version 4. here is my code

 import { HashRouter as Router, Route,browserHistory } from 'react-router-dom';
<Router history={browserHistory} >
  <App>
    <Route  path="/dashboard" component={Dashboard} />
    <Route path="/revenue" component={RevenueReports} />
</App>
 </Router>,

Upvotes: 0

Views: 4101

Answers (1)

Shubham Khatri
Shubham Khatri

Reputation: 281666

browserHistory is not available in latest react-router-dom. However BrowserRouter uses the default as browserHistory and you could simply do

import { BrowserRouter as Router, Route } from 'react-router-dom';
<Router >
  <App>
    <Route  path="/dashboard" component={Dashboard} />
    <Route path="/revenue" component={RevenueReports} />
  </App>
</Router>,

According to the docs:

A BrowserRouter is a <Router> that uses the HTML5 history API (pushState, replaceState and the popstate event) to keep your UI in sync with the URL.

Upvotes: 1

Related Questions