title: Can't stop home redirect routing for already logged user
body: <p>I’m developing a web app with angular 6, that has a login. Each user has a role and a route for each of those.</p>
  
  <p>This is my routes system.</p>
  
  <pre><code>const appRoutes: Routes = [
    {path:'', component: LoginComponent },
    // {path:'register', component: RegisterComponent, canActivate:[AuthGuard]},
    {path:'login', component: LoginComponent, canActivate:[AuthGuard]},
  
    // Paths userTypeOne
    {path:'usertypeone', canActivate:[AuthGuard], data: { expectedUserType: 'userTypeOne'}, component: userTypeOneComponent, children: [
      {path:'dashboard-userTypeOne', component: DashboardUserTypeOneComponent}
    ]},
  
    // Paths del userTypeTwo
    {path:'usertypetwo', canActivate:[AuthGuard], data: { expectedUserType: 'userTypeTwo'}, component: userTypeTwoComponent, children: [
      {path:'dashboard-usertypetwo', component: DashboardUserTypetwoComponent}
    ]},
  
  ...
  </code></pre>
  
  <p>My problem is that I read a bunch of documentation but I don’t know how to implement that when the user changes the URL directly to mydomain.com/ (path: ‘’), it goes to the same URL (mydomain.com/role) if he’s logged or to the login (path: ‘’) if he’s not. </p>
  
  <p>Right now my logic is: The user enters his username and password and it goes through a canActivate:[AuthGuard] function. There it authenticates the connection. If it’s valid it checks the ‘expectedUserType’ in the ‘data’ of the route and tries to match it with the userType from the ‘user’ that is connected (in localStorage). If it’s not a match is redirects to login, if it is it goes to the route for that specific userType.</p>
  
  <p>How can I implement that? How to make the route check if it tries to log in even if it is already logged in, stops it and redirects to the userType dashboard? I hope it's understandable.</p>
  
  <p>Here's my CanActivate</p>
  
  <pre><code>canActivate(next: ActivatedRouteSnapshot) {
          if(this.authService.loggedIn()){
              let json = JSON.parse(localStorage.user);
              this.userType = json.userType;
              if(this.userType != next.data.expectedUserType){
                  this.authService.logout();
                  this.flashMessage.show(`${next.data.expectedUserType} out of your reach`, {
                      cssClass: 'alert-success',
                      timeout: 3000
                    });
                    this.router.navigate(['/login']);
                    return false;
              }
              return true
          } else {
              this.router.navigate(['']);
              return false;
          }
      }
  </code></pre>
  
  <p>Thanks for your help.</p>