【发布时间】:2019-03-23 06:57:56
【问题描述】:
在我的组件中,我想检查用户是否已登录,如果没有,则重定向到登录页面。目前我在 componentWillMount 中进行检查和重定向。
public componentWillMount() {
if(this.props.master === null) {
this.props.history.push('./login');
}
}
但是,即使重定向确实发生了,render() 和 componentDidMount() 仍然运行,这会使我的代码崩溃,因为在那里我假设 master 不为空。
【问题讨论】:
标签: reactjs redirect react-router