简体   繁体   English

如果ionViewCanEnter在ionic3上返回false,我如何设置重定向

[英]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 在无效身份验证的情况下,应如何设置重定向到LoginPage

In angular4, I set the redirect by guards on the router 在angular4中,我通过路由器上的防护设置了重定向

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. 但是ionic3不是路由器,如果在MyApp构造函数中设置,则仅在初始化时生效,并且在以后注销用户或验证无效时无法生效。 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 所以我看到了NavController,我在ionViewCanEnter()返回false,ionic被成功拦截了请求,但是将其重定向到空白页,我想将此空白页设置为LoginPage,我尝试了navCtrl.push() ,和navCtrl.setRoot()ionViewCanEnter ,如果函数返回错误是不正确的重定向,但仍停留在空白页

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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