angular-docs-cn/packages/core/schematics/migrations/initial-navigation
Paul Gschwendtner 25f763cff8 feat(core): support TypeScript 4.3 (#42022)
Switches the repository to TypeScript 4.3 and the latest
version of tslib. This involves updating the peer dependency
ranges on `typescript` for the compiler CLI and for the Bazel
package. Tests for new TypeScript features have been added to
ensure compatibility with Angular's ngtsc compiler.

PR Close #42022
2021-06-04 11:17:09 -07:00
..
google3 feat(core): add initialNavigation schematic (#36926) 2020-10-14 12:01:07 -07:00
BUILD.bazel feat(core): add initialNavigation schematic (#36926) 2020-10-14 12:01:07 -07:00
README.md feat(core): add initialNavigation schematic (#36926) 2020-10-14 12:01:07 -07:00
collector.ts feat(core): support TypeScript 4.3 (#42022) 2021-06-04 11:17:09 -07:00
index.ts fix(core): migration error if program contains files outside of the project (#39790) 2020-11-20 12:51:19 -08:00
transform.ts fix(core): migration error if program contains files outside of the project (#39790) 2020-11-20 12:51:19 -08:00
update_recorder.ts feat(core): add initialNavigation schematic (#36926) 2020-10-14 12:01:07 -07:00
util.ts feat(core): add initialNavigation schematic (#36926) 2020-10-14 12:01:07 -07:00

README.md

initialNavigation migration

Automatically migrates the initialNavigation property of the RouterModule to the newly available options: enabledNonBlocking (default), enabledBlocking, and disabled.

Before

import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';

@NgModule({
  imports: [
    RouterModule.forRoot(ROUTES, {initialNavigation: 'legacy_disabled'}),
  ]
})
export class AppModule {
}

After

import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';

@NgModule({
  imports: [
    RouterModule.forRoot(ROUTES, {initialNavigation: 'disabled'}),
  ]
})
export class AppModule {
}

Disclaimer

The migration only covers the most common patterns where developers set the ExtraOptions#InitialNavigation option to an outdated value. Therefore, if a user declares the option using a number of other methods, e.g. shorthand notation, variable declaration, or some other crafty method, they will have to migrate those options by hand. Otherwise, the compiler will error if the types are sufficiently enforced.

The basic migration strategy is as follows:

  • legacy_disabled || false => disabled
  • legacy_enabled || true => enabledNonBlocking (new default)