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:
@ -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 {
|
||||
|
Reference in New Issue
Block a user