并排显示的命名路由器出口-带有子路由 [英] Named router outlet for side by side display - with child routes
问题描述
我的应用模块中有一个备用路由器出口,如下所示.
I have a secondary router outlet in my app module as below.
<router-outlet></router-outlet> <==== PRIMARY
<mat-sidenav-container>
<mat-sidenav mode="over">
<router-outlet name="side"></router-outlet> <=== SECONDARY NAMED OUTLET
</mat-sidenav>
</mat-sidenav-container>
然后我有一个带有子路线的功能模块,如下所示,
Then I have a feature module with child routes as below,
@NgModule({
RouterModule.forChild([
{
path: "orders",
component: OrdersComponent,
children: [
{
path: "add",
component: AddOrderComponent,
outlet: "side", <=== SAYING PATH TO USE SECONDARY OUTLET DEFINED IN APP MODULE
},
]
},
])
})
export class OrdersModule {}
我正在尝试在我的应用程序模块的辅助插座(名称为"side")内显示AddOrderComponent,但是插座未激活.
I am trying to display AddOrderComponent inside secondary outlet (name "side") in my app module, but the outlet is NOT activating.
<a [routerLink]="['../orders',{outlets: { side: ['add']}}]">
Add New Order
</a>
如果我将辅助插座移到功能模块内的任何其他组件中,则它正在工作.
If I move the secondary outlet into any other component inside the feature module it's working.
我需要在routerLink或路由定义中定义什么特殊功能才能从功能模块访问AppModule中定义的辅助路由器出口?
注意:这不是延迟加载的模块.自我引导时导入到应用程序模块中.
谢谢.
推荐答案
现在只需阅读 https://stackoverflow.com上的答案/a/53810892/3534886 解释了子路线"和我对自己感到困惑的命名路线.所以功能模块对我来说不是问题.
Just now read an answer on https://stackoverflow.com/a/53810892/3534886 explains the difference between Child Routes & Named Routes which I was confused myself. So feature module is not a problem in my case.
它说,子路由用于应出现在另一个模板中的路由.
It says, A child route is for routes that should appear within another template.
命名路由是指应该作为另一个模板的同级显示的路由,例如并排显示.
A named route is for routes that should appear as a sibling to another template, such as a side by side display.
就我而言,
我在我的应用程序组件中定义了2个并行出口(作为兄弟姐妹).但是想要功能模块的子代在同级内部进行渲染.
I defined 2 parallel outlets (as siblings) in my app component. But wanted a child of feature module to render inside sibling.
关系冲突!
这篇关于并排显示的命名路由器出口-带有子路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!