To know anything essential like WHY, WHAT and HOW, please read the document from Angular official site:
Here just summarize some key points for experienced developers to start immediately.
- In the file of app-routing.module.ts of every lazy-loading module, use forChild() but not forRoot()
- In the file of app-routing.module.ts of the root module, use loadChildren() but not XxxComponent
- In the file of app.module.ts of the root module, remove all the lazy-loading modules from “imports” list. Otherwise, lazy loading won’t work!