用于并排显示的命名路由器插座 - 带有子路由 [英] Named router outlet for side by side display - with child routes

查看:31
本文介绍了用于并排显示的命名路由器插座 - 带有子路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用模块中有一个辅助路由器插座,如下所示.

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 {}

我正在尝试在我的应用模块中的辅助出口(名称侧")内显示 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.

为了从功能模块访问 AppModule 中定义的辅助路由器出口,我需要在 routerLink 或路由定义中定义什么特殊的?

注意:这不是一个延迟加载的模块.在引导自身的同时导入应用模块.

谢谢.

推荐答案

刚刚阅读 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆