我正在努力建立以下路由结构:
Routing.module.ts
const forumRoutes: Routes = [
{
path: 'forum', component: ForumComponent, children: [
{ path: '', component: ForumListComponent },
{ path: ':categoryId', component: ForumCategoryComponent, pathMatch: 'full' },
{ path: ':threadId', component: ForumSingleComponent },
]
}
];
两条路径都运行良好,但问题是每当我单击路由器链接时
<div [routerLink]="['../thread', threadId ]">
路径会更新,但模板始终与论坛类别组件相关
{ 路径: ':categoryId', component: ForumCategoryComponent, pathMatch: 'full' },
我尝试使用路径匹配完整,但我没有产生任何效果。
我该如何注册?甚至可能吗?
pathMatch:"full"仅适用于路由段,路由器无法以这种方式按参数名称解析,因此他解析与所有分段匹配的第一个路由。
例如,如果您在浏览器中输入网址,他显然无法知道您要导航哪一个,
所以我建议你区分你最后两个孩子之间的路径(最简单的解决方法)