You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Async guards should have the option to wait for previous guards to finish #21702
There should be an option to let them execute synchronous: guard[i+1] should wait for guard[i] to finish
If guard[i] returns false all following guards should not execute
What is the motivation / use case for changing the behavior?
The example above has an authentication which needs to be done first before getting the app data. Currently it will request the App-Data immediatly without having a token.
The only solution is to use some hacky way with only one guard that executes them in sync. The feature having an array of guards is useless then.
Environment
Angular version: 5.2.x (i'm optimistic you implement this in 30minutes ;) )
Thanks, and while I agree this would be a cool feature (similar to how ui-router for AngularJS did resolves), it's not planned for this version of the router.
We will be adding better Observable support though, which should allow you to compose data to be mapped to components with whatever delays/dependencies you want.
I ran into this issue recently as well, and thought I'd share my solution in case it helps anyone else. Assuming the canActivate methods on all of your RouteGuards return Observables.
Create a Combinator abstract generic class that'll combine two other route guards
@jwhenry3 tried your solution, but throwing error.
ERROR in resources/angular/app/guards/all.guard.ts(7,14): error TS2420: Class 'AllGuard' incorrectly implements interface 'CanActivate'.
Types of property 'canActivate' are incompatible.
Type '(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) => Promise<boolean | (Observable<bool...' is not assignable to type '(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) => boolean | Promise<boolean> | Obser...'.
Type 'Promise<boolean | (Observable<boolean> & UrlTree)>' is not assignable to type 'boolean | Promise<boolean> | Observable<boolean>'.
Type 'Promise<boolean | (Observable<boolean> & UrlTree)>' is not assignable to type 'Observable<boolean>'.
Property '_isScalar' is missing in type 'Promise<boolean | (Observable<boolean> & UrlTree)>'.
I am using Angular 5.
angular-automatic-lock-bot commented on Sep 26, 2019
Activity
MickL commentedon Jan 22, 2018
Here is another (ugly) workaround i found aside for creating one Guard which combines them manually. Use nested routes:
jotatoledo commentedon Jan 22, 2018
You could wrap them in a new Guard that implements your logic.
MickL commentedon Jan 22, 2018
That is the "hacky way" i meant within "What is the motivation"
jasonaden commentedon Feb 6, 2018
Thanks, and while I agree this would be a cool feature (similar to how ui-router for AngularJS did resolves), it's not planned for this version of the router.
We will be adding better Observable support though, which should allow you to compose data to be mapped to components with whatever delays/dependencies you want.
csnate commentedon Sep 11, 2018
I ran into this issue recently as well, and thought I'd share my solution in case it helps anyone else. Assuming the
canActivatemethods on all of your RouteGuards return Observables.The Combinator can be made to include additional generic types as needed.
jwhenry3 commentedon Apr 19, 2019
I have an idea for a not-so-nasty way to accomplish this and it seems to work just fine:
and its implementation would be
marchrius commentedon Jul 25, 2019
This is an implementation supporting Promise | Observable return from await (Thanks to @jwhenry3)
pratik-joshi-cactus commentedon Aug 26, 2019
@jwhenry3 tried your solution, but throwing error.
I am using Angular 5.
angular-automatic-lock-bot commentedon Sep 26, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.