title: How to guard route by user role ? Angular
body: <p>I need to make a role base guard.</p>
  <p>If the user has <code>activeType = 0</code> he can access certain routes. If the user has <code>activeType = 1</code> he can access other routes.</p>
  <p>I already have one guard for routes but if you are logged in or not and I need to add this one for another guard but how?</p>
  <pre class="lang-typescript prettyprint-override"><code>    userData: User;
        authData: AuthData;
        constructor(private router: Router, 
                    private userService: UserService,
                    private location: Location) {
        }
      
        canActivate() {
          const userData = JSON.parse(localStorage.getItem(&quot;userData&quot;));
          const authData = JSON.parse(localStorage.getItem(&quot;authData&quot;));
          const route = this.location.path();
          if (!userData &amp;&amp; !authData) {
            return true;
          } else {
            if (route == '/login'  || route === '/register') {
              this.location.back();
              return false;
            } else {
              return true;
            }
          }
        }
      
        canLoad() {
          const userData = JSON.parse(localStorage.getItem(&quot;userData&quot;));
          const authData = JSON.parse(localStorage.getItem(&quot;authData&quot;));
          if (userData &amp;&amp; authData) {
            // logged in so return true
            return true;
          }
      
          // not logged in so redirect to login page with the return url
          this.userService.logout();
          this.router.navigate([&quot;/login&quot;]);
          return false;
        }
  </code></pre>
  <pre class="lang-typescript prettyprint-override"><code>
      const routes: Routes = [
        {
          path: &quot;route-for-user-activeType-1&quot;,
          loadChildren: () =&gt;
            import(&quot;./one/one.module&quot;).then(
              (m) =&gt; m.OneModule
            ),
          canLoad: [AuthGuard]
        },
        {
          path: &quot;route-for-user-activeType-0&quot;,
          loadChildren: () =&gt;
            import(&quot;./two/two.module&quot;).then((m) =&gt; m.twoModule),
            canActivate: [AuthGuard]
        },
        {
          path: &quot;route-path-for-user-activeType-1&quot;,
          loadChildren: () =&gt;
            import(&quot;./test/test.module&quot;).then((m) =&gt; m.testModule),
            canActivate: [AuthGuard]
        }
      ]
  
  </code></pre>