Skip to content

Async guards should have the option to wait for previous guards to finish #21702

@MickL

Description

@MickL

I'm submitting a...


[ ] Regression
[ ] Bug report
[X] Feature request
[ ] Documentation issue or request
[ ] Support request

Current behavior

When having multiple async guards(returning promise or observable) for the same path they execute at the same time:

{
  path: '',
  canActivate: [
        AuthGuard,
        DetectLanguage,
        GetAppdata,
  ],
  children: [ ... ]
}

Expected behavior

  • 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 ;) )

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions