diff --git a/packages/router/src/router.ts b/packages/router/src/router.ts
index b18c7433d31..87f314b4e4f 100644
--- a/packages/router/src/router.ts
+++ b/packages/router/src/router.ts
@@ -1245,7 +1245,6 @@ export class Router {
.next(new NavigationEnd(
t.id, this.serializeUrl(t.extractedUrl), this.serializeUrl(this.currentUrlTree)));
this.lastSuccessfulNavigation = this.currentNavigation;
- this.currentNavigation = null;
t.resolve(true);
},
e => {
diff --git a/packages/router/test/bootstrap.spec.ts b/packages/router/test/bootstrap.spec.ts
index 5c76c6b8e2c..589bdf83e4b 100644
--- a/packages/router/test/bootstrap.spec.ts
+++ b/packages/router/test/bootstrap.spec.ts
@@ -19,6 +19,10 @@ describe('bootstrap', () => {
let log: any[] = [];
let testProviders: any[] = null!;
+ @Component({template: 'simple'})
+ class SimpleCmp {
+ }
+
@Component({selector: 'test-app', template: 'root '})
class RootCmp {
constructor() {
@@ -369,7 +373,35 @@ describe('bootstrap', () => {
done();
});
- function waitForNavigationToComplete(router: Router): Promise {
- return router.events.pipe(filter((e: any) => e instanceof NavigationEnd), first()).toPromise();
- }
+ it('can schedule a navigation from the NavigationEnd event #37460', async (done) => {
+ @NgModule({
+ imports: [
+ BrowserModule,
+ RouterModule.forRoot(
+ [
+ {path: 'a', component: SimpleCmp},
+ {path: 'b', component: SimpleCmp},
+ ],
+ )
+ ],
+ declarations: [RootCmp, SimpleCmp],
+ bootstrap: [RootCmp],
+ providers: [...testProviders],
+ })
+ class TestModule {
+ }
+
+ const res = await platformBrowserDynamic([]).bootstrapModule(TestModule);
+ const router = res.injector.get(Router);
+ router.events.subscribe(() => {
+ expect(router.getCurrentNavigation()?.id).toBeDefined();
+ });
+ router.events.subscribe(async (e) => {
+ if (e instanceof NavigationEnd && e.url === '/b') {
+ await router.navigate(['a']);
+ done();
+ }
+ });
+ await router.navigateByUrl('/b');
+ });
});