ionViewCanEnter route elsewhere


#1

I am attempting to reroute my app if the user is not authenticated. I have this event (pseudo code)

ionViewCanEnter() {
if (!isAuthenticated()) {
this.navController.setRoot(LoginPage);
return false;
}
return true;
}

The Route guard is working. However the reroute doesn’t happen. It just goes to a blank page. Now if I make the following adjustment:

ionViewCanEnter() {
if (!isAuthenticated()) {
setTimeout(() => {
this.navController.setRoot(LoginPage);
});
return false;
}
return true;
}

I will get to where I want to go. I tried ngZone, it didn’t help. The setTimeout makes me uncomfortable. Is there a way to route a user to a login page if they aren’t authenticated in the ionic route guards like I could do with Angular Routing?


#2

One other note, if I do not return false, it will reroute, but you will see the first page for a brief moment which obviously is not desirable.