如何将特征模块的途径声明为另一个组成部分的孩子?
我正在重构我的Angular应用程序。我的app-routing.module.ts
有两个主要途径:
const routes: Routes = [
{path: "login", component: LoginComponent, canActivate: [IsNotLoggedGuard]},
{path: "", component: MainComponent, canActivate: [AuthGuard],children: [
{path: "orders", component: OrderComponent, children:[...]
]},
];
现在,我为新创建的ordermodule
创建了一个路由模块,
// in order-routing.module.ts
const routes = [
{path: "orders", component: OrderComponent, children:[...]
]
现在我可以删除app中的路由-routing.module.ts
,
const routes: Routes = [
{path: "login", component: LoginComponent, canActivate: [IsNotLoggedGuard]},
{path: "", component: MainComponent, canActivate: [AuthGuard],children: []},
];
但在mainComponent
中,我有一个< router-outlet></router-outlet
我想加载所有功能组件,但因此,我必须以某种方式将路由声明为子路由,但是如果每个功能模块都有多个路由模块,该怎么办?
I am refactoring my Angular App. My app-routing.module.ts
has two main routes:
const routes: Routes = [
{path: "login", component: LoginComponent, canActivate: [IsNotLoggedGuard]},
{path: "", component: MainComponent, canActivate: [AuthGuard],children: [
{path: "orders", component: OrderComponent, children:[...]
]},
];
Now, I created a routing module for the newly created OrderModule
// in order-routing.module.ts
const routes = [
{path: "orders", component: OrderComponent, children:[...]
]
now I could remove the route in app-routing.module.ts
const routes: Routes = [
{path: "login", component: LoginComponent, canActivate: [IsNotLoggedGuard]},
{path: "", component: MainComponent, canActivate: [AuthGuard],children: []},
];
but in the MainComponent
I have a <router-outlet></router-outlet
where I want to load all feature components but therefore I have to somehow declare the routes as child routes but how would I do that if I have multiple routing modules for each feature module?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您在
order> order> order.module.ts
中具有ordermodule
,并且在order>订单订购中定义的路由中导入
order> order> order> order> order code>。 Module.ts
然后您可以将
app-routing.module.ts
更新为lazy load thit the Module:Assuming you have an
OrderModule
inorder.module.ts
and inside you import theOrderRoutingModule
with the routes defined inorder-routing.module.ts
then you could update
app-routing.module.ts
to lazy load that module like this:利用
懒惰加载
,一旦用户达到特定路由,这些功能模块将被加载。app-routing.module.ts
主组件
Make use of
lazy-loading
, these feature modules will be loaded once the user hits a particular route.app-routing.module.ts
main-component