Skip to content

Change Route guard and resolver ordering to follow route parent/child hierarchy #24187

@SamuelMS

Description

@SamuelMS

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
[ ] Other... Please describe:

Current behavior

Resolve blocks are processed only distinctly after all guards are finished, meaning guards cannot protect routes that rely on asynchronous data (i.e. fetching the user) without breaking the guard/resolver paradigm.

Expected behavior

Process guards before resolvers, but follow the route parent -> child hierarchy; allow parent data to be loaded before processing authorization for child routes.

Minimal reproduction of the problem with instructions

StackBlitz: https://angular-gitter-cui2tq.stackblitz.io

Click the inline link at the top, which will attempt to load the "/somewhere" route; however, since the parent's resolver does not fire before the child's guard, the user will be undefined and you'll be redirected to the "/elsewhere" route.

What is the motivation / use case for changing the behavior?

The guard/resolver dichotomy crumbles with asynchronous data and does not allow for proper segregation of duties as described in the documenation; either guards must load data AND handle authorization, or resolvers must load data AND handle authorization. As it stands, you cannot use both as all guards are always processed first.

I actually wrote a complete breakdown in #15026, comment here -- this is probably the best explanation of why this is an issue that I can provide.

Environment


Angular version: 6.0.3


Browser:
- [x] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: 8.11.2  
- Platform:  MacOS

Others:

Metadata

Metadata

Assignees

Labels

area: routerfeatureIssue that requests a new featurefeature: under considerationFeature request for which voting has completed and the request is now under considerationfreq3: high

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions