显示嵌套路由器中的组件

编程入门 行业动态 更新时间:2024-10-26 18:22:24
本文介绍了显示嵌套路由器中的组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想路由到配置"路由器,该路由器嵌套2个插座,但是我无法找出正确的方法.

I want to route to "config" router, which is nested 2 outlets deep but I'm unable to figure out the correct way to do so.

<router> <router name="main"> <router name="config"> </router> </router> </router>

在我的routing.ts中,我创建了两种到达组件的方法:

In my routing.ts, I created 2 ways to reach the component:

export const routes: Routes = [ { // Entrypoint. path: 'Foo', component: FooComponent, canActivate: [IsServerOnlineGuard], children: [ path: 'Bar', component: BarComponent, outlet: 'main', children: [ { path: 'Smtp', component: smtpComponent, outlet: 'config' } // registered as a child ], path: 'Smtp', component: smtpComponent, outlet: 'config' }, // registered under the "main" component }, ] }, { path: '', pathMatch: 'full', redirectTo: 'CSI' }, { path: '**', redirectTo: 'CSI' }, ];

我尝试了两种导航方式.

I tried navigating there in 2 ways.

public RouteToConfigOutlet(componentName: string) { this._router.navigate([`/(main:BarComponent)/`, { outlets: { config: ['Smtp'] } }]); } public RouteToConfigOutlet(componentName: string) { this._router.navigate([``, { outlets: { main: ['BarComponent'], config: ['Smtp'] } }]); }

A,我无法显示我的组件,并试图找到到达该组件的正确方法.

Alas I'm unable to get my component to show up and am trying to find the correct way to get there.

推荐答案

我在此网站. 正确的路由方式是:

I found the answer on this website. The correct way of routing is:

router.navigate( [{ outlets: { 'main': ['BarComponent', { outlets: { 'config': ['smtpComponent'] } } ] } }]);

更多推荐

显示嵌套路由器中的组件

本文发布于:2023-11-25 17:13:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1630629.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:嵌套   路由   组件   器中

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!