我是React Router的新手,了解到有很多方法可以重定向页面:
运用 browserHistory.push("/path")
import { browserHistory } from 'react-router';
//do something...
browserHistory.push("/path");
Run Code Online (Sandbox Code Playgroud)运用 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
}
Run Code Online (Sandbox Code Playgroud)在React Router v4中,有this.context.history.push("/path")和this.props.history.push("/path").详细信息:如何在React Router v4中推送到历史记录?
我对所有这些选项感到困惑,有没有最好的方法来重定向页面?