命名路由器插座 - 父导航

时间:2017-10-06 13:15:00

标签: javascript angular typescript angular2-routing

我有一个路由器插座设置如此sitename / module /:moduleId /(child:childId)..

我现在想使用锚标签和路由器链接从插座导航到父路由,如[routerlink] = ['../../']。不幸的是,这不适用于指定的路由器插座。

目前的工作原理是我访问父快照,从查询参数中获取moduleId然后这个.. [routerLink] =“['/ module',moduleId]”

仅使用锚标记和routeLink是否可行,而不必使用javascript。

组件A(HTML)中的预期代码:

<a [routerLink]="['../../']">Back To parent</a>

组件A(HTML)中的工作代码:

 <a [routerLink]="['/module',moduleId]"> Back to parent </a>

以componentB:

ngOnInit() {
  this.moduleId = this.activatedRoute.parent.snapshot.paramMap.get('moduleType');
}

App模块

{
  path: ':moduleId', component: ComponentA, children: [{
    path: ':childId', component: ComponentB, outlet: 'child'
  }]
}

ComponentA:

<router-outlet name="child"></router-outlet>

0 个答案:

没有答案