title: How to restrict user to access unauthorized path in angular
body: <p>In my Angular app has 3 types of users: admin, brewer (vendor) &amp; end user. I want to prevent brewer from accessing admin routes, just as end users should be prevented from accessing admin routes and vendor route.</p>
  <p>How I can achieve this through angular routing.</p>
  <pre><code>const routes: Routes = [
    { path: '', redirectTo: 'home', pathMatch: 'full' },
    {
      path: 'home', component: HomeContentComponent,
    },
    { path: 'auth', loadChildren: './modules/auth/auth.module#AuthModule' },
    {
      path: 'admin',
      loadChildren: './modules/admin/admin.module#AdminModule',
      canActivate: [AuthGuard],
    },
    {
      path: 'vendor',
      loadChildren: './modules/vendor/vendor.module#VendoreModule',
      canActivate: [AuthGuard],
    },
    {
      path: 'user',
      loadChildren: './modules/user/user.module#UserModule',
      canActivate: [AuthGuard],
    }
  ]
  </code></pre>
  <p><strong>Auth Guard :</strong></p>
  <pre><code>import { Injectable } from &quot;@angular/core&quot;;
  import {
    CanActivate,
    ActivatedRouteSnapshot,
    RouterStateSnapshot,
    Router,
    CanDeactivate,
  } from &quot;@angular/router&quot;;
  import { Observable } from &quot;rxjs&quot;;
  import { AuthService } from &quot;../services/firebase/auth.service&quot;;
  
  @Injectable({ providedIn: &quot;root&quot; })
  export class AuthGuard implements CanActivate {
    constructor(public authService: AuthService, public router: Router) {}
    canActivate(
      next: ActivatedRouteSnapshot,
      state: RouterStateSnapshot
    ): Observable&lt;boolean&gt; | Promise&lt;boolean&gt; | boolean {
      // Guard for userRole is login or not
      // var Role=localStorage.getItem('role')
      let user = localStorage.getItem('toke');
      if (!user) {
        this.router.navigate([&quot;/auth/login&quot;]);
        return true;
      }
      return true;
    }
  }
  </code></pre>
  <p>I have auth guard like this how I can modify it to achieve desired functionality.</p>
  <p><strong>It would be greatly appreciated if anyone could help.</strong></p>