简体   繁体   English

Angular4模块:最佳做法

[英]Angular4 modules: Best practices

I've working on a bigger project in Angular 4.3.6 and I'm wondering what is the best way to split different navigation items into modules. 我正在Angular 4.3.6中进行一个更大的项目,我想知道将不同的导航项拆分为模块的最佳方法是什么。 All modules are lazy loaded. 所有模块都是延迟加载的。

Navigation is like (excerpt) 导航就像(摘录)

  • Administration 管理
    • Personal settings 个人设定
      • My Profile 我的简历
      • Change Password 更改密码
      • Preferences 首选项
      • Reports 报告书
    • Application Settings 应用程序设置
      • Basic Settings 基本设置
      • Advanced Settings 高级设置
      • Filters 过滤器
      • Views 观看次数
    • User Management 用户管理
      • create user 创建用户
      • list users 列出用户

I'm curious what would the best way to seperate this into modules. 我很好奇将这分成模块的最佳方法是什么。

This is a subjective question and there is no perfect answer, in my view the best way to do this is to separate by concern. 这是一个主观的问题,没有一个完美的答案,我认为做到这一点的最佳方法是分心。 Think it like this, if you load your whole application at once there will be routes and components that the user will never access. 这样想,如果立即加载整个应用程序,将会有用户永远无法访问的路由和组件。 Therefore your application will be slow because it has to load a lot of stuff the user will never use. 因此,您的应用程序将变慢,因为它必须加载用户永远不会使用的大量内容。 Ex: there is no point in loading a registration component every time if the user is only gonna register once in your application. 例如:如果用户仅在您的应用程序中注册一次,则每次加载注册组件都没有意义。 So try to group the modules by things the user may use together, so if he go to screen A he is very likely to go to screen B so it makes sense to put then in the same module and lazy load it. 因此,请尝试按用户可能一起​​使用的模块对模块进行分组,因此,如果他转到屏幕A,则很有可能会转到屏幕B,因此有必要将其放在同一模块中并延迟加载。 Also try to create a shared module so you can put what is common to more than one module to avoid duplication. 另外,请尝试创建一个共享模块,以便您可以将多个模块的共同之处放在避免重复的位置。 As well as try to keep your modules as small as possible. 并尽量使模块尽可能小。

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

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