简体   繁体   English

Angular 延迟加载功能模块路由

[英]Angular Lazy Loading Feature Module Routes

I have a confusion regarding lazy loading a feature module.我对延迟加载功能模块感到困惑。 I do understand the concept of lazy loading a feature module but my question is shall i lazy load every route inside the feature module?我确实理解延迟加载功能模块的概念,但我的问题是我应该延迟加载功能模块内的每条路线吗?

For Example i have a feature called 'Announcement'.例如,我有一个名为“公告”的功能。 It has a list, create, edit and details component.它有一个列表、创建、编辑和详细信息组件。 What i did is that i lazy loaded every route inside the feature module along with the feature module itself.我所做的是我懒惰地加载了功能模块中的每条路由以及功能模块本身。

Day by day my application getting bigger so it takes a while to serve or build the application since it goes through each and every module.我的应用程序一天天变大,因此服务或构建应用程序需要一段时间,因为它会经历每个模块。

So should i lazy loaded every route inside the feature module?那么我应该延迟加载功能模块中的每条路线吗?

To answer to your question, The lazy loading is to enhance the performance of the application.回答您的问题,延迟加载是为了提高应用程序的性能。 So our application will be split into multiple functional modules and implement lazy loading.所以我们的应用会被拆分成多个功能模块,实现延迟加载。 By doing so, based the navigation to particular route, it will load only that particular things which is required.通过这样做,基于对特定路线的导航,它将仅加载所需的特定内容。 (It will create a chunk.js) and if we re route to this again, it will not reload every thing again as its already loaded. (它会创建一个 chunk.js),如果我们再次路由到这个,它不会像已经加载的那样重新加载所有东西。 You can see a demo in below url:您可以在以下网址中看到演示:

https://angular-auxillary-route-lazy-load-example.stackblitz.io https://angular-auxillary-route-lazy-load-example.stackblitz.io

For more detailed info refer below links:有关更多详细信息,请参阅以下链接:

https://angular.io/guide/lazy-loading-ngmodules https://angular.io/guide/lazy-loading-ngmodules

https://medium.com/@thiago.reis/how-to-implement-lazy-loading-in-angular-c8dcbf165561 https://medium.com/@thiago.reis/how-to-implement-lazy-loading-in-angular-c8dcbf165561

We don't need to create modules for each component, we need to do this only for a functional modules.我们不需要为每个组件创建模块,我们只需要为一个功能模块做这个。 Example: LoginModule (that handles all the login functionalities), UserModule (which tracks user information)...示例:LoginModule(处理所有登录功能)、UserModule(跟踪用户信息)...

Hope this helps.希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM