定义父元素上的RouterLink时,Angular 2 RouterLink无法导航

时间:2019-04-26 13:52:49

标签: javascript angular routing nested-routes

我将路由配置如下:

{
path: 'myworkshop',
children: [
  { path: 'tagged/:tagTypeId', component: TaggedMessageListComponent, canActivate: [RouteGuard], resolve: { tagType: TagTypeResolver }, data: { allowed: ['isr'], context: SearchContexts.Isr } },
  { path: 'tagged', component: TaggedMessageListComponent, canActivate: [RouteGuard], data: { allowed: ['isr'], context: SearchContexts.Isr } },
],
canActivate: [RouteGuard],
data: { allowed: ['isr'] }

}

在我的模板中,我只能访问<tree-child-brach /myworkshop/a82a716f-9019-4fb1-acb6-9a68f652ebfd

  <tree-child-branch  [name]="'Tagged Messages'" [routerLink]="['/myworkshop/', 'tagged']" ></tree-child-branch>

tree-child是一个模板组件,我想在其中访问其他路由器链接:

<li [routerLink]="getTagRouteParams(t.id)" routerLinkActive="active">
                    <span class="nav-tree-child-data" >{{name}}</span>
</li>



  getTagRouteParams(tagId: string) {
if (this.context == SearchContexts.Inv)
  return ['/myworkshop/tagged', tagId];

if (this.context == SearchContexts.Isr) {
  return ['/myworkshop/tagged', tagId];
}

throw new Error('Invalid context. ' + this.context);

}

问题是我可以访问路由myworkshop/tagged/a82a716f-9019-4fb1-acb6-9a68f652ebfd,但是单击<li [routerLink]="getTagRouteParams(t.id)" ></li>时却没有路由到该链接

0 个答案:

没有答案