最佳答案
我是 React 路由器的新手,我知道有很多方法可以重定向一个页面:
使用 browserHistory.push("/path")
import { browserHistory } from 'react-router';
//do something...
browserHistory.push("/path");
Using this.context.router.push("/path")
class Foo extends React.Component {
constructor(props, context) {
super(props, context);
//do something...
}
redirect() {
this.context.router.push("/path")
}
}
Foo.contextTypes = {
router: React.PropTypes.object
}
In React Router v4, there's this.context.history.push("/path")
and this.props.history.push("/path")
. Details: How to push to History in React Router v4?
I'm so confused by all these options, is there a best way to redirect a page?