fix(router): cancel navigation when at least one resolver completes with no "next" emission (#24621)

This change aligns behavior for resolvers which return EMPTY. Currently EMPTY resolvers have inconsistent behavior:
- One resolver that returns EMPTY => won't navigate and just ends on ResolveStart router event.
- Two resolvers where both return EMPTY => throws "Error: Uncaught (in promise): EmptyError: no elements in sequence"
- Two resolvers where one returns a value and the other one returns EMPTY => Navigates successfully.
With this change any EMPTY resolver will cancel navigation.

BREAKING CHANGE: Any resolver which return EMPTY will cancel navigation.
If you want to allow the navigation to continue, you will need to update the resolvers to emit
some value, (i.e. defaultIfEmpty(...), of(...), etc).
PR Close #24195

PR Close #24621
This commit is contained in:
Martin Sikora
2020-04-17 11:48:19 +02:00
committed by Alex Rickabaugh
parent 12fcc7cafe
commit d9c4840a9c
5 changed files with 296 additions and 25 deletions

View File

@ -2956,7 +2956,7 @@ Update the `CrisisDetailComponent` to get the crisis from the `ActivatedRoute.d
<code-example path="router/src/app/crisis-center/crisis-detail/crisis-detail.component.ts" header="src/app/crisis-center/crisis-detail/crisis-detail.component.ts (ngOnInit v2)" region="ngOnInit"></code-example>
Note the following two important points:
Note the following three important points:
1. The router's `Resolve` interface is optional.
The `CrisisDetailResolverService` doesn't inherit from a base class.
@ -2964,6 +2964,8 @@ The router looks for that method and calls it if found.
1. The router calls the resolver in any case where the the user could navigate away so you don't have to code for each use case.
1. Returning an empty `Observable` in at least one resolver will cancel navigation.
The relevant Crisis Center code for this milestone follows.
<code-tabs>