import Router from 'next/router';
class App extends NextApp {
constructor(props) {
super(props);
this.state = {
isLogin: false
}
}
componentDidMount() {
if (JSON.parse(sessionStorage.getItem("APIKEY"))) {
return
}
if (!this.state.isLogin) {
Router.push('/login')
}
}
}
问问题
38 次
1 回答
2
官方建议是使用constructor
.
(见https://reactjs.org/docs/react-component.html#unsafe_componentwillmount)
于 2020-11-18T09:05:04.153 回答