diff --git a/modules/@angular/router/src/router.ts b/modules/@angular/router/src/router.ts index 9b075af18e..fd99c2f069 100644 --- a/modules/@angular/router/src/router.ts +++ b/modules/@angular/router/src/router.ts @@ -596,7 +596,9 @@ export class Router { const id = ++this.navigationId; this.navigations.next({id, rawUrl, prevRawUrl, extras, resolve, reject, promise}); - return promise; + // Make sure that the error is propagated even though `processNavigations` catch + // handler does not rethrow + return promise.catch((e: any) => Promise.reject(e)); } private executeScheduledNavigation({id, rawUrl, prevRawUrl, extras, resolve, diff --git a/modules/@angular/router/test/integration.spec.ts b/modules/@angular/router/test/integration.spec.ts index 57a2cb2d58..d35d2c49e8 100644 --- a/modules/@angular/router/test/integration.spec.ts +++ b/modules/@angular/router/test/integration.spec.ts @@ -7,7 +7,7 @@ */ import {CommonModule, Location} from '@angular/common'; -import {Component, NgModule, NgModuleFactoryLoader} from '@angular/core'; +import {Component, Injector, NgModule, NgModuleFactoryLoader} from '@angular/core'; import {ComponentFixture, TestBed, async, fakeAsync, inject, tick} from '@angular/core/testing'; import {expect} from '@angular/platform-browser/testing/matchers'; import {Observable} from 'rxjs/Observable'; @@ -620,6 +620,19 @@ describe('Integration', () => { expectEvents(recordedEvents, [[NavigationStart, '/invalid'], [NavigationError, '/invalid']]); }))); + it('should not swallow errors', fakeAsync(inject([Router], (router: Router) => { + const fixture = createRoot(router, RootCmp); + + router.resetConfig([{path: 'simple', component: SimpleCmp}]); + + router.navigateByUrl('/invalid'); + expect(() => advance(fixture)).toThrow(); + + router.navigateByUrl('/invalid2'); + expect(() => advance(fixture)).toThrow(); + }))); + + it('should replace state when path is equal to current path', fakeAsync(inject([Router, Location], (router: Router, location: Location) => { const fixture = createRoot(router, RootCmp);