I've defined a resolver for my signup route:
import {IsLoggedin} from './share/is-loggedin.service';
const appRoutes: Routes = [
{path: 'signup', resolve: [IsLoggedin], component: SignupComponent}
]
In the resolver I'm redirecting to a certain page if the user is logged in:
resolve(route: ActivatedRouteSnapshot, routerState: RouterStateSnapshot) {
this.authService.isUserAuthenticated()
.subscribe(
(res: any) => {
if (res === true) {
this.router.navigate(['/main-board']);
}
}
);
}
But, angular loads the SignupComponent anyway before redirecting to the main-board page.
Note: I've tried with CanActivate guard, but it still can't redirect without loading the componenet as isUserAuthenticated() method returns a Observable and doesn't work synchronized way.
I really want to know whether it is possible in angular to redirect to the main-board page without loading the SignupComponent.
Can it be done smoothly in angular 2/4 ?
I would really appreciate if someone help me.
CanActivateguard still it can't redirect without loading the componenet asisUserAuthenticated()method returns aObservableand doesn't work synchronized way