Skip to content

docs(ivy): add /migration/lazy-routes to AIO - #29730

Closed
alexeagle wants to merge 1 commit into
angular:masterfrom
alexeagle:fix-lazy-routes
Closed

alexeagle wants to merge 1 commit into
angular:masterfrom
alexeagle:fix-lazy-routes

Conversation

@alexeagle

Copy link
Copy Markdown
Contributor

No description provided.

@alexeagle
alexeagle requested a review from a team April 5, 2019 17:30
@mary-poppins

Copy link
Copy Markdown

You can preview ea288cf at https://pr29730-ea288cf.ngbuilds.io/.
You can preview 01f483e at https://pr29730-01f483e.ngbuilds.io/.

@alexeagle

Copy link
Copy Markdown
Contributor Author

note: still discussing in slack #tools-fix-lazy-routes whether we want to have the migration built-in

# Updating Angular Lazy Routes

When we first introduced lazy routes, there wasn't browser support for dynamically loading additional JavaScript.
Angular created our own scheme using the syntax `loadChildren: './lazy/lazy.module#LazyModule'` and built complex tooling to support it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we pull out the old syntax into a code snippet? Otherwise it's hard to find what pattern is necessary to change.

1. Why isn't this migration run automatically by `ng update`?

This migration is optional in Angular 8.
Since we expect the majority of users will not opt-into Ivy, we don't want to introduce the risk of breaking your application in case your code or a library you use depends on the current string-based syntax in some way.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Since we expect the majority of users will not opt-into Ivy, we don't want to introduce the risk of breaking your application in case your code or a library you use depends on the current string-based syntax in some way.
Since we expect the majority of users will not opt into Ivy, we don't want to introduce the risk of breaking your application in case your code or a library you use depends on the current string-based syntax in some way.

@gkalpak gkalpak left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More work is needed if you want to add a new migration sub-path (e.g. you need more changes to show the SideNav, show a ToC, etc.). But, we should first discuss whether we want to introduce a new sub-path.

@petebacondarwin

Copy link
Copy Markdown
Contributor

@gkalpak - @alexeagle and I discussed the navigation but for now he just wanted to have a URL available.


When we first introduced lazy routes, there wasn't browser support for dynamically loading additional JavaScript.
Angular created our own scheme using the syntax `loadChildren: './lazy/lazy.module#LazyModule'` and built complex tooling to support it.
Now that EcmaScript dynamic import is a standard and is supported in many browsers, it's time for Angular applications to use this new syntax.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EcmaScript -> ECMAScript for consistency?


When we first introduced lazy routes, there wasn't browser support for dynamically loading additional JavaScript.
Angular created our own scheme using the syntax `loadChildren: './lazy/lazy.module#LazyModule'` and built complex tooling to support it.
Now that EcmaScript dynamic import is a standard and is supported in many browsers, it's time for Angular applications to use this new syntax.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dynamic import is a standard

It is NOT a standard, which got stuck in stage 3 due to security issue. (Need to land Realms first)

1. Install the migrator:

```sh
$ npm install @phenomnomnominal/angular-lazy-routes-fix -D

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it better to use full-form of CLI options? People may forget about what it stands for.

@ngbot ngbot Bot added this to the needsTriage milestone Apr 17, 2019
Angular created our own scheme using the syntax `loadChildren: './lazy/lazy.module#LazyModule'` and built complex tooling to support it.
Now that EcmaScript dynamic import is a standard and is supported in many browsers, it's time for Angular applications to use this new syntax.

> Updating your lazy routes to dynamic import is *required* in order to use Angular Ivy.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment it is not required anymore, just highly recommended.

@jbogarthyde jbogarthyde Apr 19, 2019 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be where to put the new text from #29955:


The string syntax for the loadChildren route specification is deprecated in Angular version 8, in favor of new syntax that uses an import statement.
As part of updating an application to Angular version 8, it is recommended that you update to the new import syntax.
You can use angular-lazy-routes-fix to perform the transformation automatically.

For example:

const routes: Routes = [{
  path: 'lazy',
  // The string syntax for loadChildren is deprecated:
  //   loadChildren: './lazy/lazy.module#LazyModule'
  // This has been transformed to use the new import syntax.
  loadChildren: () => import('./lazy/lazy.module').then(m => m.LazyModule)
}];

Ivy supports both the deprecated string syntax and the recommended import syntax.
If you have updated your lazy routes to use the import() statement but are not using Ivy,
make sure your default build options in angular.json include the flag "experimentalImportFactories": true.


1. Why isn't this migration run automatically by `ng update`?

This migration is optional in Angular 8.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

angular/angular-cli#14181 doesn't seem to be optional currently.

@filipesilva filipesilva mentioned this pull request Apr 19, 2019
3 of 14 tasks
@alexeagle alexeagle closed this Apr 24, 2019
@angular-automatic-lock-bot

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Sep 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants