Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2/4: How to restrict access to Login Route if user is already logged in?

Tags:

I have the following route definition.

export const Routes = RouterModule.forChild([
    {
        path: 'login',
        component: LoginComponent
    },
    {
        path: 'protected',
        canActivate: [AuthGuardService],
        component: ProtectedComponent
    },
    {
        path: 'home',
        component: HomeComponent,
        canActivate: [AuthGuardService],
    },
]);

I have successfully implement AuthGuardService which restrict access to a protected route if user is not logged in.

What I am trying to achieve is, if user is already logged in and accessed the Login Route, I want it to redirect to another route like homepage.