无法在同一URL下注册两条动态路由

时间:2018-05-04 13:47:27

标签: angular angular-ui-router router

我正在努力建立以下路线结构:

Routing.module.ts

const forumRoutes: Routes = [
  {
    path: 'forum', component: ForumComponent, children: [
      { path: '', component: ForumListComponent },
      { path: ':categoryId', component: ForumCategoryComponent, pathMatch: 'full' },
      { path: ':threadId', component: ForumSingleComponent },
    ]
  }
];

两条路径都运行良好,但问题是每当我点击routerLink

<div [routerLink]="['../thread', threadId ]">

路径更新但模板始终属于ForumCategoryComponent

  

{path:':categoryId',组件:ForumCategoryComponent,pathMatch:   'full'},

我尝试使用pathMatch,但我没有产生任何效果。

我该如何注册?它甚至可能吗?

1 个答案:

答案 0 :(得分:0)

pathMatch:'full'仅适用于路段,路由器无法通过参数名解析,因此他解析了匹配所有段的第一条路线。

例如,如果您在浏览器中输入网址,他显然无法知道您要浏览哪个网址,

因此,我建议您区分最后两个孩子之间的路径(最简单的解决方法)