简体   繁体   中英

How can i set the redirect if ionViewCanEnter return false on ionic3

How should I set the redirect to the LoginPage in the case of invalid authentication

In angular4, I set the redirect by guards on the router

But ionic3 is no router, If set up in MyApp constructor, this can only take effect at initialization, and can not come into effect when the user is later logged out or when the authentication is invalid. This solution is not suitable for me. So I saw NavController, I returned to false in ionViewCanEnter() , ionic is successfully intercepted the request, but it is redirected to a blank page, I want to send this blank page is set to LoginPage, I tried navCtrl.push() , and navCtrl.setRoot() in ionViewCanEnter , if the function return false is not correct redirect, it still remain in the blank page

How can i set the redirect if invalid authentication

setTimeout(() => {
    this.navCtrl.setRoot('UnauthorizedPage');
});

This works for me.

Work for me

setTimeout(() => {
   this.app.getRootNav().setRoot('LoginPage');
}, 200);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM