当用户登录(成功)并且将他从AWS Cognito重定向到我的secondPage时,我遇到了问题,它将重新加载firstPage直到状态更新(2秒),然后将其重定向到secondPage。用户到secondPage而不将他重定向到firstPage?
我在可能存在问题的代码中写了一条注释。
class AuthRouter extends Component {
constructor(props){
super(props);
this.state = {
authenticated: this.props.authStore.isAuthenticated()
};
}
handleAuthChange = authenticated => {
this.setState({ authenticated: authenticated });
};
componentWillMount() {
this.props.authStore.subscribe(this.handleAuthChange);
};
componentWillUnmount() {
this.props.authStore.unsubscribe();
};
render() {
return (
<div>
/// The problem happens here, it checks the state, couple of seconds it updates to true then it redirects to secondPage, I need a delay until the state is updated... or how this can be changed.
{!this.state.authenticated && (
<Router component={firstPage}/>
)}
{this.state.authenticated && (
<Router component={secondPage}/>
)}
</div>
);
}
}