fix(router): do not finish bootstrap until all the routes are resolved (#14608)

Fixes #12162
closes #14155
This commit is contained in:
Victor Berchet
2017-02-20 18:37:38 -08:00
committed by GitHub
parent c2e0f71a78
commit 2a191cae2d
12 changed files with 304 additions and 154 deletions

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {PlatformLocation} from '@angular/common';
import {LOCATION_INITIALIZED, PlatformLocation} from '@angular/common';
import {APP_INITIALIZER, InjectionToken, NgZone} from '@angular/core';
import {WebWorkerPlatformLocation} from './platform_location';
@ -25,9 +25,18 @@ export const WORKER_APP_LOCATION_PROVIDERS = [
multi: true,
deps: [PlatformLocation, NgZone],
},
{
provide: LOCATION_INITIALIZED,
useFactory: locationInitialized,
deps: [PlatformLocation],
},
];
function appInitFnFactory(platformLocation: WebWorkerPlatformLocation, zone: NgZone): () =>
export function locationInitialized(platformLocation: WebWorkerPlatformLocation) {
return platformLocation.initialized;
}
export function appInitFnFactory(platformLocation: WebWorkerPlatformLocation, zone: NgZone): () =>
Promise<boolean> {
return () => zone.runGuarded(() => platformLocation.init());
}

View File

@ -22,6 +22,8 @@ export class WebWorkerPlatformLocation extends PlatformLocation {
private _hashChangeListeners: Array<Function> = [];
private _location: LocationType = null;
private _channelSource: EventEmitter<Object>;
public initialized: Promise<any>;
private initializedResolve: () => void;
constructor(
brokerFactory: ClientMessageBrokerFactory, bus: MessageBus, private _serializer: Serializer) {
@ -48,6 +50,7 @@ export class WebWorkerPlatformLocation extends PlatformLocation {
}
}
});
this.initialized = new Promise(res => this.initializedResolve = res);
}
/** @internal **/
@ -58,6 +61,7 @@ export class WebWorkerPlatformLocation extends PlatformLocation {
.then(
(val: LocationType) => {
this._location = val;
this.initializedResolve();
return true;
},
err => { throw new Error(err); });