尝试导航到同级路线时,角子路线相对导航错误

时间:2019-10-08 18:39:42

标签: angular

使用angular 8.x;

tldr;

以下内容:

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

导致:

ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'details'

绝对导航正常工作:

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

长版本...

请考虑以下功能模块的布线:

const searchRoutes: Routes = [
  {
    path: 'search',
    component: SearchComponent,
    children: [
      {
        path: '',
        component: PersonSearchComponent,
        children: [
          {
            path: 'details',
            component: DetailsComponent
          },
          {
            path: '',
            component: QueryComponent
          }
        ]
      }
    ]
  }
];

app-routing.module:

const routes: Routes = [
  {path: '', redirectTo: '/search', pathMatch: 'full'},
];

localhost:4200/正确地重定向到localhost:4200/search。显示QueryComponent的模板。

使用相对导航如何从'details'内部导航到QueryComponent路线? (同级导航)

根据angular docs,此方法应该有效:

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

0 个答案:

没有答案