title: Passing parameters into Guard Angular 2
body: <p>I have an app that I have setup with an Authentication Guard to make sure users cannot access the app unless they have logged in, like so</p>
  
  <pre><code>import { Injectable } from '@angular/core';
  import {
      CanActivate, Router,
      ActivatedRouteSnapshot,
      RouterStateSnapshot,
      CanActivateChild } from '@angular/router';
  import { AuthContext } from './auth-context.service';
  
  @Injectable()
  export class AuthGuard implements CanActivate {
          constructor(private router: Router, private authContext: AuthContext) { }
  
      canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
          // Check to see if a user has a valid JWT
          if (this.authContext.userInfo !== undefined &amp;&amp; this.authContext.userInfo.isAuthenticated) {
              // If they do, return true and allow the user to load the home component
              return true;
          }
  
          // If not, they redirect them to the login page
          this.router.navigate(['/login']);
          return false;
      }
  
      canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
          return this.canActivate(route, state);
      }
  }
  </code></pre>
  
  <p>I want to add another guard for Authorization that will check if the user is in a certain role. Currently I am hiding the link in navigation based on this role.</p>
  
  <pre><code> &lt;div *ngIf="userInRole('Admin')"&gt;
               This is secret stuff
   &lt;/div&gt;
  </code></pre>
  
  <p>But if a user knows a route, they can just plug it into the url. How would I add my "userInRole()" type functionality to a Guard? I would have to pass the role name and do the check in code. Do Guards support params?</p>