fix(Router): do not kill event-emitter on navigation failure
Closes #7692 Closes #7532 Closes #7692
This commit is contained in:
parent
ce013a3dd9
commit
cbeeff2bd6
@ -276,7 +276,7 @@ export class Router {
|
|||||||
if (result) {
|
if (result) {
|
||||||
return this.commit(instruction, _skipLocationChange)
|
return this.commit(instruction, _skipLocationChange)
|
||||||
.then((_) => {
|
.then((_) => {
|
||||||
this._emitNavigationFinish(instruction.toRootUrl());
|
this._emitNavigationFinish(instruction.component);
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -284,9 +284,13 @@ export class Router {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private _emitNavigationFinish(url): void { ObservableWrapper.callEmit(this._subject, url); }
|
private _emitNavigationFinish(instruction: ComponentInstruction): void {
|
||||||
|
ObservableWrapper.callEmit(this._subject, {status: 'success', instruction});
|
||||||
|
}
|
||||||
/** @internal */
|
/** @internal */
|
||||||
_emitNavigationFail(url): void { ObservableWrapper.callError(this._subject, url); }
|
_emitNavigationFail(url: string): void {
|
||||||
|
ObservableWrapper.callEmit(this._subject, {status: 'fail', url});
|
||||||
|
}
|
||||||
|
|
||||||
private _afterPromiseFinishNavigating(promise: Promise<any>): Promise<any> {
|
private _afterPromiseFinishNavigating(promise: Promise<any>): Promise<any> {
|
||||||
return PromiseWrapper.catchError(promise.then((_) => this._finishNavigating()), (err) => {
|
return PromiseWrapper.catchError(promise.then((_) => this._finishNavigating()), (err) => {
|
||||||
|
@ -135,14 +135,31 @@ export function main() {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
it('should trigger the onError callback of a router change subscription if the URL does not match a route',
|
it('should pass an object containing the component instruction to the router change subscription after a successful navigation',
|
||||||
inject([AsyncTestCompleter], (async) => {
|
inject([AsyncTestCompleter], (async) => {
|
||||||
var outlet = makeDummyOutlet();
|
var outlet = makeDummyOutlet();
|
||||||
|
|
||||||
router.registerPrimaryOutlet(outlet)
|
router.registerPrimaryOutlet(outlet)
|
||||||
.then((_) => router.config([new Route({path: '/a', component: DummyComponent})]))
|
.then((_) => router.config([new Route({path: '/a', component: DummyComponent})]))
|
||||||
.then((_) => {
|
.then((_) => {
|
||||||
router.subscribe((_) => {}, (url) => {
|
router.subscribe(({status, instruction}) => {
|
||||||
|
expect(status).toEqual('success');
|
||||||
|
expect(instruction).toEqual(jasmine.objectContaining({urlPath: 'a', urlParams: []}));
|
||||||
|
async.done();
|
||||||
|
});
|
||||||
|
(<SpyLocation>location).simulateHashChange('a');
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should pass an object containing the bad url to the router change subscription after a failed navigation',
|
||||||
|
inject([AsyncTestCompleter], (async) => {
|
||||||
|
var outlet = makeDummyOutlet();
|
||||||
|
|
||||||
|
router.registerPrimaryOutlet(outlet)
|
||||||
|
.then((_) => router.config([new Route({path: '/a', component: DummyComponent})]))
|
||||||
|
.then((_) => {
|
||||||
|
router.subscribe(({status, url}) => {
|
||||||
|
expect(status).toEqual('fail');
|
||||||
expect(url).toEqual('b');
|
expect(url).toEqual('b');
|
||||||
async.done();
|
async.done();
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user