[Angular 2] Keynote: Lazy Routing -- NGCONF

So How to do lazy loading for router in Angular 2.

 

The nomarl way to write a router in Angular 2:

[Angular 2] Keynote: Lazy Routing -- NGCONF_第1张图片

You have SimpleCmp and UserCmp as child components. You also import {SimpleCmp, UserCmp} from 'xxxxxx'.

It will not be lazy loaded. Because you already have the reference to the child component.

 

But it turn out to be very easy to enable the lazy loading:

[Angular 2] Keynote: Lazy Routing -- NGCONF_第2张图片

Just add '' to SimpleCmp and UserCmp. 

Then you need to follow the convention of how to name the folder.

[Angular 2] Keynote: Lazy Routing -- NGCONF_第3张图片

 

The '+' symbol means those folders are lazy loaded. So Component is called UserCmp, the folder should be named as 'user-cmp'. OKOK, not tooo bad.

 

[Angular 2] Keynote: Lazy Routing -- NGCONF_第4张图片

你可能感兴趣的:([Angular 2] Keynote: Lazy Routing -- NGCONF)