Revert "refactor(router): remove deprecated initialNavigation options (#18781)"

This reverts commit d76761bf01.
This commit is contained in:
Miško Hevery
2017-08-22 18:39:06 -05:00
parent 7236095f6f
commit a80ecf6a77
3 changed files with 106 additions and 6 deletions

View File

@ -218,14 +218,24 @@ export function provideRoutes(routes: Routes): any {
* The bootstrap is blocked until the initial navigation is complete.
* * 'disabled' - the initial navigation is not performed. The location listener is set up before
* the root component gets created.
* * 'legacy_enabled'- the initial navigation starts after the root component has been created.
* The bootstrap is not blocked until the initial navigation is complete. @deprecated
* * 'legacy_disabled'- the initial navigation is not performed. The location listener is set up
* after @deprecated
* the root component gets created.
* * `true` - same as 'legacy_enabled'. @deprecated since v4
* * `false` - same as 'legacy_disabled'. @deprecated since v4
*
* The 'enabled' option should be used for applications unless there is a reason to have
* more control over when the router starts its initial navigation due to some complex
* initialization logic. In this case, 'disabled' should be used.
*
* The 'legacy_enabled' and 'legacy_disabled' should not be used for new applications.
*
* @experimental
*/
export type InitialNavigation = 'enabled' | 'disabled';
export type InitialNavigation =
true | false | 'enabled' | 'disabled' | 'legacy_enabled' | 'legacy_disabled';
/**
* @whatItDoes Represents options to configure the router.
@ -244,7 +254,7 @@ export interface ExtraOptions {
useHash?: boolean;
/**
* Enables/Disables the initial navigation (enabled by default).
* Disables the initial navigation.
*/
initialNavigation?: InitialNavigation;
@ -322,12 +332,14 @@ export class RouterInitializer {
const router = this.injector.get(Router);
const opts = this.injector.get(ROUTER_CONFIGURATION);
if (opts.initialNavigation === 'disabled') {
if (this.isLegacyDisabled(opts) || this.isLegacyEnabled(opts)) {
resolve(true);
} else if (opts.initialNavigation === 'disabled') {
router.setUpLocationChangeListener();
resolve(true);
} else if (
opts.initialNavigation === 'enabled' || typeof opts.initialNavigation === 'undefined') {
} else if (opts.initialNavigation === 'enabled') {
router.hooks.afterPreactivation = () => {
// only the initial navigation should be delayed
if (!this.initNavigation) {
@ -360,11 +372,26 @@ export class RouterInitializer {
return;
}
if (this.isLegacyEnabled(opts)) {
router.initialNavigation();
} else if (this.isLegacyDisabled(opts)) {
router.setUpLocationChangeListener();
}
preloader.setUpPreloading();
router.resetRootComponentType(ref.componentTypes[0]);
this.resultOfPreactivationDone.next(null !);
this.resultOfPreactivationDone.complete();
}
private isLegacyEnabled(opts: ExtraOptions): boolean {
return opts.initialNavigation === 'legacy_enabled' || opts.initialNavigation === true ||
opts.initialNavigation === undefined;
}
private isLegacyDisabled(opts: ExtraOptions): boolean {
return opts.initialNavigation === 'legacy_disabled' || opts.initialNavigation === false;
}
}
export function getAppInitializer(r: RouterInitializer) {