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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With