Skip to content

Commit 9b61379

Browse files
atscottdylhunn
authored andcommitted
fix(router): Ensure initial navigation clears current navigation when blocking (#49572)
The navigation transition clears the current navigation in the finalize operator of the current navigation Observer. This commit both completes the `bootstrapDone` observable and updates the transition to only take 1 emit from the completed navigation. Either of these changes on their own would fix the issue. The latter is a preventative measure in case a mistake like the former is made again. fixes #49567 PR Close #49572
1 parent 08979e4 commit 9b61379

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

packages/router/src/navigation_transition.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,11 @@ export class NavigationTransitions {
654654
this.rootContexts, router.routeReuseStrategy,
655655
(evt: Event) => this.events.next(evt)),
656656

657+
// Ensure that if some observable used to drive the transition doesn't
658+
// complete, the navigation still finalizes This should never happen, but
659+
// this is done as a safety measure to avoid surfacing this error (#49567).
660+
take(1),
661+
657662
tap({
658663
next: (t: NavigationTransition) => {
659664
completed = true;

packages/router/src/provide_router.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ export function getBootstrapListener() {
210210
router.resetRootComponentType(ref.componentTypes[0]);
211211
if (!bootstrapDone.closed) {
212212
bootstrapDone.next();
213+
bootstrapDone.complete();
213214
bootstrapDone.unsubscribe();
214215
}
215216
};

packages/router/test/bootstrap.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,9 @@ describe('bootstrap', () => {
257257
const router = ref.injector.get(Router);
258258
const data = router.routerState.snapshot.root.firstChild!.data;
259259
expect(data['test']).toEqual('test-data');
260+
// Also ensure that the navigation completed. The navigation transition clears the
261+
// current navigation in its `finalize` operator.
262+
expect(router.getCurrentNavigation()).toBeNull();
260263
});
261264
await Promise.all([bootstrapPromise, navigationEndPromise]);
262265
});

0 commit comments

Comments
 (0)