Previously, I was able to reroute user (eg on successful login) using browser history:
import { browserHistory } from 'react-router'
browserHistory.replace('/home')
In the new react-router I am no longer able to import browserHistory, what is the alternative way to achieve my goal?
import { Router, Route } from 'react-router'
import { createBrowserHistory } from 'history'
export default () => (
<Router history={createBrowserHistory()} >
<Route exact path="/" component={MainPageComponent} />
</Router>
)
In MainPageComponent you can use this.props.history.push('/home').
Learn about router history here https://github.com/ReactTraining/history
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.