componentDidMount() {
if (sessionStorage.loggedInUser === undefined && localStorage.loggedInUser === undefined) {
this.props.history.push("/");
}
//Check if user owns the car to see if we should send the ajax
ajax.request.get("/cars/all").then((allCars) => {
this.setState({
allCars: allCars
})
})
}
componentWillMount() {
if (sessionStorage.loggedInUser === undefined && localStorage.loggedInUser === undefined) {
this.props.history.push("/");
}
}
后我有这样的方法,i。由该代码是通过槽他们调试看到,但重定向之后它进入到渲染方法,并开始执行它。为什么?Reactjs,渲染()被执行重定向
你期待它由componentDidMount中移除,因为要重定向但它仍然在后台渲染页面,这是你的意思? – johnjerrico
是的,它仍然执行的渲染方法,并得到了一个未定义例外 – Alexander
据我可以理解“推”不删除旧页,“替换”做 – johnjerrico