feat(router): Make RootRouter disposable to allow cleanup of Location subscription. ROUTER_PROVIDERS now automatically disposes of the RootRouter when the application is disposed.

Closes #4915
This commit is contained in:
Alex Rickabaugh
2015-10-26 11:01:02 -07:00
parent 2674eaca51
commit 2e059dc916
3 changed files with 27 additions and 11 deletions

View File

@ -467,12 +467,13 @@ export class Router {
export class RootRouter extends Router {
/** @internal */
_location: Location;
_locationSub: Object;
constructor(registry: RouteRegistry, location: Location, primaryComponent: Type) {
super(registry, null, primaryComponent);
this._location = location;
this._location.subscribe((change) =>
this.navigateByUrl(change['url'], isPresent(change['pop'])));
this._locationSub = this._location.subscribe(
(change) => this.navigateByUrl(change['url'], isPresent(change['pop'])));
this.registry.configFromComponent(primaryComponent);
this.navigateByUrl(location.path());
}
@ -489,6 +490,13 @@ export class RootRouter extends Router {
}
return promise;
}
dispose(): void {
if (isPresent(this._locationSub)) {
ObservableWrapper.dispose(this._locationSub);
this._locationSub = null;
}
}
}
class ChildRouter extends Router {