I want to create a complex router guard that checks if the user is authenticated in the web application but, if so, it checks also other condition and for each true condition it redirects to a page (that is however under the same router guard). For better explaining this inside the router guard I have to do something like this:
canActivate(state: RouterStateSnapshot) {
if(isAuthenticated()) {
if(!isEmailVerified) {
// redirect to the "check the email" page
}
else if(!isProfileComplete()) {
// redirect to profile completion page
}
else {
// redirect to user homepage
}
return true;
} else {
// redirect login
return false;
}
}
The problem actually is that this does not work because each redirect brings to a page protected by this guard and then each redirect calls another redirect and it ends with a infinite loop. I've already tried to check inside the conditions if the state.url is not the same that we redirect to inside the condition body but this does not work. Is there a simple solution to do this?