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

This reverts commit 541de26f7e because it introduced a regression.

Closes #14681, #14588
This commit is contained in:
Victor Berchet
2017-02-27 14:37:33 -08:00
committed by Igor Minar
parent b658fa9ea0
commit de36f8a3b9
11 changed files with 156 additions and 300 deletions

View File

@ -5,14 +5,14 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {APP_BOOTSTRAP_LISTENER, ComponentRef, OpaqueToken} from '@angular/core';
import {Router} from '@angular/router';
import {APP_BOOTSTRAP_LISTENER, ApplicationRef, OpaqueToken} from '@angular/core';
import {ExtraOptions, ROUTER_CONFIGURATION, ROUTER_INITIALIZER, Router, RouterPreloader} from '@angular/router';
import {UpgradeModule} from '@angular/upgrade/static';
/**
* @whatItDoes Creates an initializer that in addition to setting up the Angular
* @whatItDoes Creates an initializer that in addition to setting up the Angular 2
* router sets up the ngRoute integration.
*
* @howToUse
@ -35,17 +35,38 @@ import {UpgradeModule} from '@angular/upgrade/static';
* @experimental
*/
export const RouterUpgradeInitializer = {
provide: APP_BOOTSTRAP_LISTENER,
multi: true,
useFactory: locationSyncBootstrapListener,
deps: [UpgradeModule]
provide: ROUTER_INITIALIZER,
useFactory: initialRouterNavigation,
deps: [UpgradeModule, ApplicationRef, RouterPreloader, ROUTER_CONFIGURATION]
};
/**
* @internal
*/
export function locationSyncBootstrapListener(ngUpgrade: UpgradeModule) {
return () => { setUpLocationSync(ngUpgrade); };
export function initialRouterNavigation(
ngUpgrade: UpgradeModule, ref: ApplicationRef, preloader: RouterPreloader,
opts: ExtraOptions): Function {
return () => {
if (!ngUpgrade.$injector) {
throw new Error(`
RouterUpgradeInitializer can be used only after UpgradeModule.bootstrap has been called.
Remove RouterUpgradeInitializer and call setUpLocationSync after UpgradeModule.bootstrap.
`);
}
const router = ngUpgrade.injector.get(Router);
const ref = ngUpgrade.injector.get(ApplicationRef);
router.resetRootComponentType(ref.componentTypes[0]);
preloader.setUpPreloading();
if (opts.initialNavigation === false) {
router.setUpLocationChangeListener();
} else {
router.initialNavigation();
}
setUpLocationSync(ngUpgrade);
};
}
/**
@ -56,14 +77,7 @@ export function locationSyncBootstrapListener(ngUpgrade: UpgradeModule) {
*
* @experimental
*/
export function setUpLocationSync(ngUpgrade: UpgradeModule) {
if (!ngUpgrade.$injector) {
throw new Error(`
RouterUpgradeInitializer can be used only after UpgradeModule.bootstrap has been called.
Remove RouterUpgradeInitializer and call setUpLocationSync after UpgradeModule.bootstrap.
`);
}
export function setUpLocationSync(ngUpgrade: UpgradeModule): void {
const router: Router = ngUpgrade.injector.get(Router);
const url = document.createElement('a');
@ -72,4 +86,4 @@ export function setUpLocationSync(ngUpgrade: UpgradeModule) {
url.href = next;
router.navigateByUrl(url.pathname);
});
}
}