Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 2 Router Guards order

Angular 2 router guards can be defined in an array. for example:

<code>
 canActivate: ['CanAlwaysActivateGuard','AuthGuard']
</code>

following are my questions:

  1. what will be the order of execution for both the guards.
  2. if i want to execute AuthGuard only if CanAlwaysActivateGuard returns true, would that be possible.
like image 214
Mahesh Avatar asked Aug 10 '17 16:08

Mahesh


1 Answers

what will be the order of execution for both the guards.

They will be run synchronously without waiting for each other.

if i want to execute AuthGuard only if CanAlwaysActivateGuard returns true, would that be possible.

No, it's not possible with current implementation. As a workaround you can create a wrapper guards to run your guards in order.

Also see this How to wait for guards in Angular.

like image 108
Max Koretskyi Avatar answered Sep 18 '22 19:09

Max Koretskyi