这是我的路由器:
render() {
if (this.props.commonStore.appLoaded) {
return (
<div>
<Header />
<Switch>
<Route path="/services" component={MyServices} />
<Route path="/payments" component={Payments} />
<Route path="/order" component={Order} />
<Route path="/support" component={Support} />
<Route path="/send_ticket/:department_id" component={SendTicket} />
<Route path="/servicedetails" component={ServiceDetails} />
<Route path="/editor/:slug?" component={Editor} />
<Route path="/article/:id" component={Article} />
<Route path="/tickets/" component={Ticket} />
<Route path="/ticket/:id" component={InnerTicket} />
<PrivateRoute path="/settings" component={Settings} />
<Route path="/@:username" component={Profile} />
<Route path="/@:username/favorites" component={Profile} />
<Route path="/home" component={Home} />
</Switch>
<Footer />
</div>
);
}
return (
<div>
<Switch>
<Route path="/logout" component={LogOut} />
<Route path="/register" component={Register} />
<Route path="/login" component={Login} />
<Route path="/" component={RedirectLogin} />
</Switch>
</div>
);
}
当我使用此方法重定向任何路由以使用RedirectLogin组件登录页面时,一切正常:
componentDidMount(){
this.props.history.replace('/login');
}
但是当我在登录后使用相同的方法重定向时,它不会重定向,这是我的登录处理程序:
handleSubmitForm = (e) => {
e.preventDefault();
this.props.authStore.login()
.then(() => this.props.history.replace('/home'));
};