title: Angular Route Metadata in Guards
body: <p>Back in angularjs (using ui-router). You could add metadata to your routes and use those in routechanges.</p>
  
  <p>In angular there are Guards for this, but I cannot seem to figure out how to get the metadata out of the route definition.</p>
  
  <p>To give you a more concrete example, I would like to be able to add metadata to a route, let's say required roles and or permissions and have a guard do the heavy lifting.</p>
  
  <p>Route definitions:</p>
  
  <pre><code>RouterModule.forChild([
      {
          path: '',
          component: MyComponent,
          data: {
              permissions: ["view"],
              roles: ["admin", "user"]
          }
      },
      ...
  ]);
  </code></pre>
  
  <p>And then in my Guard:</p>
  
  <pre><code>constructor(private myService: MyService, private router: Router) {}
  
  canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
      //How to get a hold of the data defined for the current route ?
      console.log(route.data); //returns an empty object
  }
  </code></pre>