auto_route_library
auto_route_library copied to clipboard
Question about guards - order of execution is sequential or parallel?
Are guards executed sequentially, one after another, in the order of definition? Or are they executed in parallel with each other?
If I define two guards on a route, like so: guards: [AuthStatusPrefetcher, AuthGuard]
, can the second guard rely on the data fetched by the first guard, if the first guard only calls resolver.next()
once the required data is fetched?
It seems to me that the guards are executed sequentially, in order of definition.
I would like to know if that's intentional, and if I can confidently build on top of this behavior, for example by using the above pattern.
Yes, you can do that, but not directly passing data between guards, instead you need to cache the result somewhere from the first route guard and then retrieve it to the next. And yes, guards are executed sequentially in order of definition, a series of completers waiting to be completed by resolver.next()
. So if your first guard prefetching yields error, you can call resolver.next(false)
so it will not execute the next guard, and redirect somewhere else.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions