[英]How to implement lazy loading for a multi-tier application
I have a 3-tier application and I'm having problems with the architecture.我有一个 3 层应用程序,但我遇到了架构问题。 Here are the example urls:
以下是示例网址:
/ (base url)
dummy-configuration/
dummy-configuration/dummyModel
dummy-configuration/dummyModel/dummyData
So I've got a dummy config module, an dummyModel module and a dummyData component.所以我有一个虚拟配置模块、一个dummyModel模块和一个dummyData组件。 However, I only put router outlet directives in the app component html and the dummy config html.
但是,我只将路由器出口指令放在应用程序组件 html和虚拟配置html 中。 This is where I first went wrong, I believe.
这是我第一次出错的地方,我相信。 Don't I need a router outlet at each level?
我不需要每个级别的路由器插座吗?
My app-routing.module file lazy loads my dummy configuration module :我的app-routing.module文件延迟加载我的虚拟配置模块:
{
path: 'dummy-configuration',
loadChildren: () =>
import('./dummy-configuration/dummy-configuration.module').then(
(p) => p.DummyConfigurationModule
),
}
The dummy configuration routing module then lazy loads its children:然后,虚拟配置路由模块延迟加载其子模块:
children: [
{
path: {PATH},
loadChildren: () =>
import('../dummyModel/dummy-model.module').then((m) => m.DummyModule),
}
]
And the Dummy module will load its children: Dummy 模块将加载其子模块:
children: [
{
path: 'childOne',
component: childOneComponent,
},
{
path: 'childTwo',
component: childTwoComponent,
}
]
What I've achieved is lazy loading of the dummy config and "dummy model" modules.我所取得的是延迟加载虚拟配置和“虚拟模型”模块。 But what I want is also to lazy load the component routes for the dummy model and I don't know how to do it.
但我想要的也是延迟加载虚拟 model的组件路由,我不知道该怎么做。 How can I re-architect this correctly?
我怎样才能正确地重新架构这个? Honestly, I'm a little lost.
老实说,我有点失落。
If you use the children
attribute you do need a router-outlet in which the children can be rendered.如果您使用
children
属性,您确实需要一个可以在其中呈现子项的路由器插座。 In your case though, you can just add the first module just like you showed by loading it at the plan-configuration
path.但是,在您的情况下,您可以像在
plan-configuration
路径中加载它一样添加第一个模块。
The second module you can just load at the plan-configuration/fsa
path, wit will then correctly handle the profile
and dependents
routes without needing another router-outlet but instead being rendered in the main one.第二个模块您可以在
plan-configuration/fsa
路径中加载,然后它将正确处理profile
和dependents
路由,而不需要另一个路由器出口,而是在主出口中呈现。
In short, just import the ra-fsa
module in app-routing
with plan-configuration/fsa
as your path.简而言之,只需在
app-routing
中导入ra-fsa
模块,并使用plan-configuration/fsa
作为路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.