fix(router): canceled navigations should return a promise that is resolved with false
This commit is contained in:
parent
3f44377f2f
commit
855f3afb28
@ -276,6 +276,7 @@ export class Router {
|
|||||||
return new Promise((resolvePromise, rejectPromise) => {
|
return new Promise((resolvePromise, rejectPromise) => {
|
||||||
let updatedUrl: UrlTree;
|
let updatedUrl: UrlTree;
|
||||||
let state: RouterState;
|
let state: RouterState;
|
||||||
|
let navigationIsSuccessful;
|
||||||
applyRedirects(url, this.config)
|
applyRedirects(url, this.config)
|
||||||
.mergeMap(u => {
|
.mergeMap(u => {
|
||||||
updatedUrl = u;
|
updatedUrl = u;
|
||||||
@ -305,7 +306,8 @@ export class Router {
|
|||||||
.forEach((shouldActivate: boolean) => {
|
.forEach((shouldActivate: boolean) => {
|
||||||
if (!shouldActivate || id !== this.navigationId) {
|
if (!shouldActivate || id !== this.navigationId) {
|
||||||
this.routerEvents.next(new NavigationCancel(id, this.serializeUrl(url)));
|
this.routerEvents.next(new NavigationCancel(id, this.serializeUrl(url)));
|
||||||
return Promise.resolve(false);
|
navigationIsSuccessful = false;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
new ActivateRoutes(state, this.currentRouterState).activate(this.outletMap);
|
new ActivateRoutes(state, this.currentRouterState).activate(this.outletMap);
|
||||||
@ -320,14 +322,13 @@ export class Router {
|
|||||||
this.location.go(path);
|
this.location.go(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return Promise.resolve(true);
|
navigationIsSuccessful = true;
|
||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
() => {
|
() => {
|
||||||
this.routerEvents.next(
|
this.routerEvents.next(
|
||||||
new NavigationEnd(id, this.serializeUrl(url), this.serializeUrl(updatedUrl)));
|
new NavigationEnd(id, this.serializeUrl(url), this.serializeUrl(updatedUrl)));
|
||||||
resolvePromise(true);
|
resolvePromise(navigationIsSuccessful);
|
||||||
|
|
||||||
},
|
},
|
||||||
e => {
|
e => {
|
||||||
this.routerEvents.next(new NavigationError(id, this.serializeUrl(url), e));
|
this.routerEvents.next(new NavigationError(id, this.serializeUrl(url), e));
|
||||||
|
@ -731,13 +731,17 @@ describe('Integration', () => {
|
|||||||
advance(fixture);
|
advance(fixture);
|
||||||
expect(location.path()).toEqual('/team/22');
|
expect(location.path()).toEqual('/team/22');
|
||||||
|
|
||||||
router.navigateByUrl('/team/33');
|
let successStatus;
|
||||||
|
router.navigateByUrl('/team/33').then(res => successStatus = res);
|
||||||
advance(fixture);
|
advance(fixture);
|
||||||
expect(location.path()).toEqual('/team/33');
|
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);
|
advance(fixture);
|
||||||
expect(location.path()).toEqual('/team/33');
|
expect(location.path()).toEqual('/team/33');
|
||||||
|
expect(canceledStatus).toEqual(false);
|
||||||
})));
|
})));
|
||||||
|
|
||||||
it('works (componentless route)',
|
it('works (componentless route)',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user