fix(router): add an option to disable initial navigation

This commit is contained in:
vsavkin
2016-08-25 08:48:31 -07:00
committed by Victor Berchet
parent 2fc5c57b31
commit a2deafc50f
4 changed files with 33 additions and 18 deletions

View File

@ -262,6 +262,22 @@ export class Router {
this.navigateByUrl(this.location.path(true), {replaceUrl: true});
}
/**
* Sets up the location change listener
*/
setUpLocationChangeListener(): void {
// Zone.current.wrap is needed because of the issue with RxJS scheduler,
// which does not work properly with zone.js in IE and Safari
this.locationSubscription = <any>this.location.subscribe(Zone.current.wrap((change: any) => {
const tree = this.urlSerializer.parse(change['url']);
// we fire multiple events for a single URL change
// we should navigate only once
return this.currentUrlTree.toString() !== tree.toString() ?
this.scheduleNavigation(tree, {skipLocationChange: change['pop'], replaceUrl: true}) :
null;
}));
}
/**
* Returns the current route state.
*/
@ -439,19 +455,6 @@ export class Router {
(_) => this.runNavigate(url, extras.skipLocationChange, extras.replaceUrl, id));
}
private setUpLocationChangeListener(): void {
// Zone.current.wrap is needed because of the issue with RxJS scheduler,
// which does not work properly with zone.js in IE and Safari
this.locationSubscription = <any>this.location.subscribe(Zone.current.wrap((change: any) => {
const tree = this.urlSerializer.parse(change['url']);
// we fire multiple events for a single URL change
// we should navigate only once
return this.currentUrlTree.toString() !== tree.toString() ?
this.scheduleNavigation(tree, {skipLocationChange: change['pop'], replaceUrl: true}) :
null;
}));
}
private runNavigate(
url: UrlTree, shouldPreventPushState: boolean, shouldReplaceUrl: boolean,
id: number): Promise<boolean> {