So, this is what my AuthGuard looks like:
canLoad(route: Route) {
return this.store.select(fromRoot.getIsAuth).pipe(take(1));
}
I check Authentication information from app.component and simply return an Observable boolean.
I don't want to subscribe to this to reroute, I don't want to use router.navigate inside AuthGuard so I want to keep it a simple Guard.
Is there a way to reroute inside routing-module, that simply routes to an alternate path if AuthGuard returns false?
As far as I know you have to do the navigation in the guard. No way to configure the router to do what you want. But you don't need to subscribe. You can use tap to do the navigation.
canLoad(route: Route) {
return this.store.select(fromRoot.getIsAuth)
.pipe(
take(1),
tap(loggedIn => {
if (!loggedIn) {
this.router.navigate(['/login']);
}
})
);
}