reactjs - 如何在 IonAlert 上的 onDidDIsmiss 方法上路由到另一个组件
问题描述
当用户访问仪表板组件时,我想检查用户是否已登录,如果未登录,该组件会显示一个警报,提示用户登录或取消。当他单击确认时,应自动将用户重定向/路由到登录组件。这是我的代码:
... state:{isLoggedIn:false,showAlert:true}
componentDidMount(){
const checkLogin=this.props.location.state;
if(checkLogin){
this.setState({isLoggedIn:true,showAlert:false})
}
}
//render part
<IonAlert isOpen={this.state.showAlert} onDidDismiss={()=>(
<Route path="/login" component={Login}/>
)} animated="true" header="connection" message="Vous devez etre connecté"
buttons={['Login']}>
</IonAlert>
在此先感谢您的帮助!