How to fix "the router no longer uses hash history alert history"?

I use browser history and here is my code in routes.js

export default ( <Router history={browserHistory}> <Route path="/" component={Main}> <Route path="home/:username" component={Home}> <IndexRoute component={HomeContent}></IndexRoute> <Route path="widget/:second" component={Widget}></Route> <Route path="email/:second" component={Email}> <Route path="compose" component={ComposeEmail}></Route> <IndexRoute component={CheckEmail}></IndexRoute> </Route> <Route path="social/:second" component={Social}></Route> <Route path="calendar/:second" component={Calendar}></Route> </Route> <IndexRoute component={Login}></IndexRoute> </Route> </Router> ); 

and I used this.context.router.push ('/') to do the navigation. and I don’t know why this warning continues to be displayed in my console?

  "Warning: [react-router] `Router` no longer defaults the history prop to hash history. Please use the `hashHistory` singleton instead." 

I already read the documentation at https://github.com/reactjs/react-router/blob/master/upgrade-guides/v2.0.0.md#no-default-history , but that really doesn't help.

I appreciated any help :)

+6
source share
1 answer

You need to use hashHistory instead of browserHistory . Given that you use import syntax, you can import hashHistory from react-router to replace browserHistory .

 import { hashHistory, Router, ... } from 'react-router'; const history = new hashHistory(); export default ( <Router history={history}> ... </Router> ); 
0
source

All Articles