0

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>,
2
  • 2
    Maybe don't use HashRouter as Router if you don't want to route with hashes in the URL. Commented Dec 7, 2017 at 11:41
  • Use BrowserRouter instead of HashRouter. You don't need to explicitly set browserHistory with BrowserRouter. Commented Dec 7, 2017 at 11:41

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.