在儿童路线Angular 2之间导航

Dav*_*oal 11 url-redirection angular

我似乎无法在子路线之间导航.

路由器概述:

path: 'parent', component: parentComponent,
        children: [
            { path: '', redirectTo: 'child1', pathMatch: 'full' },
            { path: 'child1', component: child1Component },
            { path: 'child2', component: child2Component },
            { path: 'new/:type', component: child3Component },

            { path: '**', component: PageNotFoundComponent }
        ]
Run Code Online (Sandbox Code Playgroud)

我在child1组件中尝试导航到新的/类型路由,如下所示:

this._router.navigate(['new', objType], { relativeTo: this._route });
Run Code Online (Sandbox Code Playgroud)

但我一直得到错误:无法匹配任何路线.网址细分:'新/资产'.

如果我手动插入网址,它工作正常.

非常感谢帮助,谢谢!

Gün*_*uer 16

您可以使用 ../

this._router.navigate(['../new', objType], { relativeTo: this._route });
Run Code Online (Sandbox Code Playgroud)


Mil*_*lad 7

this.router.navigate(['../../new'], { relativeTo: this._route })
Run Code Online (Sandbox Code Playgroud)

要么

this.router.navigate(['/parent/new'])
Run Code Online (Sandbox Code Playgroud)

或者使用锚标记:

 <a [routerLink]=" ['../../new'] ">
      Go to new
 </a>
Run Code Online (Sandbox Code Playgroud)

要么 :

 <a [routerLink]=" ['/parent/new'] ">
      Go to new
 </a>
Run Code Online (Sandbox Code Playgroud)