我的应用程序中有一条路线,格式为localhost/opportunity/:id/volunteers
. 我想构建一个routerLink
导航到同一级别的不同页面(即localhost/opportunity/:id/waitlist
)。按照API 文档Routerlink
中概述的选项,我得到的印象是routerLink
表单中的arouterLink="./volunteers"
应该链接到我当前所在的同一页面。因此,routerLinkActive
forrouterLink="./volunteers"
应该表示链接是活动的。但它并没有这样做......
相关路线如下所示:
const routes: Routes = [
{
path: 'opportunity',
children: [
{
path: ':id',
children: [
{
path: 'volunteers',
component: VolunteersComponent
},
{
path: 'waitlist',
component: WaitlistComponent
},
{
etc . . .
}
]
}
]
}
];
routerLink="./volunteers"
似乎导航到localhost/volunteers
不存在的。我也尝试过 , , 等形式的链接routerLink="../../volunteers"
(routerLink="../volunteers"
它们routerLink="././volunteers"
也不起作用,不是我认为它们会起作用)。
关于我做错了什么有什么建议吗?显然,我可以:id
手动从链接中提取 ' 并将其插入(类似于routerLink="['opportunity', extractedId, 'volunteers']"
),但这感觉是错误的方式,我不想:id
在我的应用程序中手动提取 '。似乎我只是做错了什么。我已经搜索了一段时间,但还没有找到这个问题的答案。
小编辑:我还要说这个模块直接加载到根模块中。
更新:
当我尝试 arouterLink="../"
时,它显示为该localhost/opportunity/:id/volunteers
url 处于活动状态,但单击该链接会将我带回主页(即localhost/
)。我非常确信我的路由器只认为我的应用程序中有一个子级别(即localhost/opportunity/:id/volunteers
并且localhost/calendar
似乎都是 的直接子级localhost
。而localhost/opportunity/:id/volunteers
应该是 的直接子级localhost/opportunity/:id
。我需要通过router
'forChild()
方法加载路由吗?将其视为子级?换router
一种说法,是否有可能因为该模块的所有路由都加载在同一个forChild()
块中,所以它们被视为同一级别的子级?