angular-cn/packages/router/src
Alex Rickabaugh c61df39323 feat(router): deprecate loadChildren:string (#30073)
The proposed ES dynamic import() is now supported by the Angular CLI and the
larger toolchain. This renders the `loadChildren: string` API largely
redundant, as import() is far more natural, is less error-prone, and is
standards compliant. This commit deprecates the `string` form of
`loadChildren` in favor of dynamic import().

DEPRECATION:

When defining lazy-loaded route, Angular previously offered two options for
configuring the module to be loaded, both via the `loadChildren` parameter
of the route. Most Angular developers are familiar withthe `string` form of
this API. For example, the following route definition configures Angular to
load a `LazyModule` NgModule from `lazy-route/lazy.module.ts`:

```
[{
  path: 'lazy',
  loadChildren: 'lazy-route/lazy.module#LazyModule',
}]
```

This "magic string" configuration was previously necessary as there was
no dynamic module loading standard on the web. This has changed with the
pending standardization of dynamic `import()` expressions, which are now
supported in the Angular CLI and in web tooling in general. `import()`
offers a more natural and robust solution to dynamic module loading. The
above example can be rewritten to use dynamic `import()`:

```
[{
  path: 'lazy',
  loadChildren: () => import('./lazy-route/lazy.module').then(mod => mod.LazyModule),
}]
```

This form of lazy loading offers significant advantages in terms of:

* type checking via TypeScript
* simplicity of generated code
* future potential to run natively in supporting browsers
  (see: [caniuse: dynamic import()](https://caniuse.com/#feat=es6-module-dynamic-import))

As a result, Angular is deprecating the `loadChildren: string` syntax in
favor of ES dynamic `import()`. An automatic migration will run during
`ng upgrade` to convert your existing Angular code to the new syntax.

PR Close #30073
2019-04-24 17:06:05 -07:00
..
components build: enable bundle_dts for router package (#28833) 2019-03-07 07:30:44 -08:00
directives refactor(router): change RouterLinkActive impl to account for upcoming ivy breaking change (#28560) 2019-02-08 16:42:45 -08:00
operators fix(router): add `relativeLinkResolution` to `recognize` operator (#26990) 2018-11-13 16:18:08 -08:00
utils feat(router): add predicate function mode for runGuardsAndResolvers (#27682) 2018-12-18 13:55:06 -08:00
apply_redirects.ts feat(router): allow guards to return UrlTree as well as boolean (#26521) 2018-10-31 19:51:50 -04:00
config.ts feat(router): deprecate loadChildren:string (#30073) 2019-04-24 17:06:05 -07:00
create_router_state.ts fix(router): cache route handle if found (#22475) 2018-04-23 13:35:59 -07:00
create_url_tree.ts Revert "fix(router): change processing url tree children condition (#26243)" (#27516) 2018-12-06 09:17:20 -08:00
events.ts feat(router): add a Navigation type available during navigation (#27198) 2018-11-30 13:34:55 -08:00
index.ts feat(router): deprecate loadChildren:string (#30073) 2019-04-24 17:06:05 -07:00
interfaces.ts docs: fix grammatical errors in the guides and API documentation (#29928) 2019-04-22 17:32:30 -07:00
private_export.ts build: enable bundle_dts for router package (#28833) 2019-03-07 07:30:44 -08:00
recognize.ts Revert "fix(router): process empty path segment when preceding a named outlet (#26243)" (#27516) 2018-12-06 09:17:20 -08:00
route_reuse_strategy.ts docs: convert all `@experimental` tags to `@publicApi` tags (#26595) 2018-10-19 14:35:52 -07:00
router.ts fix(router): adjust setting navigationTransition when a new navigation cancels an existing one (#29636) 2019-04-01 12:11:55 -07:00
router_config_loader.ts fix(router): removed obsolete TODO comment (#29085) 2019-03-05 09:44:40 -08:00
router_module.ts docs: update extra options available for RouterModule.forRoot() method (#29846) 2019-04-17 17:25:31 -07:00
router_outlet_context.ts docs: update router to use `@publicApi` tags (#26595) 2018-10-19 14:35:53 -07:00
router_preloader.ts docs: update router to use `@publicApi` tags (#26595) 2018-10-19 14:35:53 -07:00
router_scroller.ts fix(router): default scroll position restoration to disabled (#25586) 2018-08-21 10:48:14 -07:00
router_state.ts docs(router): use pipe in activatedRoute example (#29752) 2019-04-08 17:18:06 -07:00
shared.ts docs: update router to use `@publicApi` tags (#26595) 2018-10-19 14:35:53 -07:00
url_handling_strategy.ts docs: convert all `@experimental` tags to `@publicApi` tags (#26595) 2018-10-19 14:35:52 -07:00
url_tree.ts docs: update router to use `@publicApi` tags (#26595) 2018-10-19 14:35:53 -07:00
version.ts docs: update router to use `@publicApi` tags (#26595) 2018-10-19 14:35:53 -07:00