Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Router canActivate with more than 1 guard

Tags:

Does angular(v 4.1.1) router canActivate take more than one function

{
   path: '',
   component: SomeComponent,
   canActivate: [guard1, guard2, ...]
}

should something like that work? If not they why would it be in a list if its suppose to take just one guard

Because I have something similar and even though guard1 returns false, guard2 will still be executed.

Thanks in advance

Angular 4.1.1

like image 829
phacic Avatar asked Jun 16 '17 10:06

phacic


1 Answers

This should work but I believe the guards are executed in parallel not in a sequence. So the second one does not wait until the first one return a value. This should not really affect you if your guards are synchronous, but if they are asynchronous, you will run into this "issue".

If you need your guards to depend on each other, you could separate the common part of the check and all your guards could call that logic. But I think in most cases this should not even be necessary, because if only one of them fails, the route is not activated.

like image 117
Vladimir Zdenek Avatar answered Oct 09 '22 10:10

Vladimir Zdenek