Reactjs 安装前如何更改isLogin?
官方建议使用Reactjs 安装前如何更改isLogin?,reactjs,next.js,next-router,Reactjs,Next.js,Next Router,官方建议使用构造函数 (见附件) import Router from 'next/router'; class App extends NextApp { constructor(props) { super(props); this.state = { isLogin: false } } componentDidMount() { if (JSON.parse(sessionStorage.getItem("APIK
构造函数
(见附件)
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')
}
}
}