Categories
Uncategorized

Using multiple guards for a route in Angular

The canActivate( ) method which should be overridden, should return only one of the following types

  • Observable<boolean>
  • Promise<boolean>
  • boolean

The multiple routes work like an ‘&&’ condition in javascript, i.e., angular won’t execute the later guards, if the first one fails.

app-routing.module

guard-one.guard

guard-two.guard

The login service that is being used above can be somewhat like this:

guard-two.guard

For these files to work, you need to add them to the app.module.ts and also use in the main component where you would like to use the router.