diff --git a/modules/@angular/router/src/router.ts b/modules/@angular/router/src/router.ts index 62db733054..0429164b41 100644 --- a/modules/@angular/router/src/router.ts +++ b/modules/@angular/router/src/router.ts @@ -276,6 +276,7 @@ export class Router { return new Promise((resolvePromise, rejectPromise) => { let updatedUrl: UrlTree; let state: RouterState; + let navigationIsSuccessful; applyRedirects(url, this.config) .mergeMap(u => { updatedUrl = u; @@ -305,7 +306,8 @@ export class Router { .forEach((shouldActivate: boolean) => { if (!shouldActivate || id !== this.navigationId) { this.routerEvents.next(new NavigationCancel(id, this.serializeUrl(url))); - return Promise.resolve(false); + navigationIsSuccessful = false; + return; } new ActivateRoutes(state, this.currentRouterState).activate(this.outletMap); @@ -320,14 +322,13 @@ export class Router { this.location.go(path); } } - return Promise.resolve(true); + navigationIsSuccessful = true; }) .then( () => { this.routerEvents.next( new NavigationEnd(id, this.serializeUrl(url), this.serializeUrl(updatedUrl))); - resolvePromise(true); - + resolvePromise(navigationIsSuccessful); }, e => { this.routerEvents.next(new NavigationError(id, this.serializeUrl(url), e)); diff --git a/modules/@angular/router/test/router.spec.ts b/modules/@angular/router/test/router.spec.ts index 6708db4869..a394e15a85 100644 --- a/modules/@angular/router/test/router.spec.ts +++ b/modules/@angular/router/test/router.spec.ts @@ -731,13 +731,17 @@ describe('Integration', () => { advance(fixture); expect(location.path()).toEqual('/team/22'); - router.navigateByUrl('/team/33'); + let successStatus; + router.navigateByUrl('/team/33').then(res => successStatus = res); advance(fixture); expect(location.path()).toEqual('/team/33'); + expect(successStatus).toEqual(true); - router.navigateByUrl('/team/44'); + let canceledStatus; + router.navigateByUrl('/team/44').then(res => canceledStatus = res); advance(fixture); expect(location.path()).toEqual('/team/33'); + expect(canceledStatus).toEqual(false); }))); it('works (componentless route)',