Angular 2路由器导航' ../'移动到父级的根状态

时间:2017-06-27 09:23:19

标签: angular routing

我有布局:' / home',2页:' / home / sample / list'和' / home / sample / details'和他们的布局:' / home / sample'。我试图从' / home / sample / details'导航到父状态。到' / home / sample'然后重定向到' / home / sample / list'。但是,当我尝试使用类似于' ../'它把我带到了' / home'。我做错了什么?

const appRoutes: Routes = [
    { path: '', redirectTo: '/home', pathMatch: 'full' },
    { path: 'home', component: HomeComponent, children: [
       { path: 'sample', component: SampleComponent, children: [
          { path: '', redirectTo: 'list', pathMatch: 'full' },
          { path: 'details', component: SampleDetailsComponent },
          { path: 'list', component: SampleListComponent },
       ]}
    ] },
    { path: '**', component: PageNotFoundComponent }
];

用户点击按钮后我想让他回到父状态(如后退按钮)

this.router.navigate(['../']);

1 个答案:

答案 0 :(得分:1)

如果您想进行相对路由

您必须按relativeTo定义,这将导航到上一级

this.router.navigate(['../', { relativeTo: this.route }]);