Hello,
I’m using ionic 3.20
I think ionViewCanEnter doesn’t work as expected. My assumption was that the view won’t be rendered if it returns false. What I see is that the view is rendered en displayed for a short time (0.5 second?), then I’m redirected to the login page. Preferably I like the view not being rendered if it returns false.
I implemented it like this:
ionViewCanEnter() {
return this.auth.authenticated(this.navCtrl);
}
And auth.authenticated is implemented like this:
authenticated(nav: NavController): boolean | Promise<any> {
return this.storage.get("token").then(token => {
console.log('from storage: ' + token);
if (token == null) {
setTimeout(() => {
nav.setRoot("SignInPage")
}, 0);
} else {
return true;
}
}).catch(() => {
setTimeout(() => {
nav.setRoot("SignInPage")
}, 0);
return false;
});
}
Please let me know how I can improve this.
Roy