Reactjs 如何使用react路由器dom实现重定向?
我试着用Reactjs 如何使用react路由器dom实现重定向?,reactjs,redirect,router,react-router-dom,Reactjs,Redirect,Router,React Router Dom,我试着用 <Redirect to = 'loginPage' /> 但它并没有把我引向任何地方。我该怎么办 请帮助我您有两个重定向选项: 选项1: 如本例所示,使用: <Redirect to={{ pathname: '/loginpage' }} /> componentDidUpdate() { if (this.props.authenticated === false) { this.props.history.
<Redirect to = 'loginPage' />
但它并没有把我引向任何地方。我该怎么办
请帮助我您有两个重定向选项: 选项1: 如本例所示,使用
:
<Redirect
to={{
pathname: '/loginpage'
}}
/>
componentDidUpdate() {
if (this.props.authenticated === false) {
this.props.history.push("/loginpage");
}
}
myComponent = withRouter(
ServicePlanSelect
);
请注意,要使用此选项,该组件必须是
的子组件。否则,您必须使用withRouter()
HOC,如本例所示:
<Redirect
to={{
pathname: '/loginpage'
}}
/>
componentDidUpdate() {
if (this.props.authenticated === false) {
this.props.history.push("/loginpage");
}
}
myComponent = withRouter(
ServicePlanSelect
);
使用Please post your code.test通过像这样将/添加到loginPage另一个解决方案是使用browserHistory推送。Google it您会发现大量的示例Direct组件需要渲染才能正常工作,如果您使用的是类内方法,则可以参考