为什么我的路由器导航功能在角度8中不起作用?

问题描述 投票:1回答:1

我正在尝试重定向到这样的另一个组件:

HomeComponent

  checkUrl(reference) {   
    if (reference != this.ref) {
      this.router.navigate(['/еrror']);
    }
  }

这是我的路由器模块

const routes: Routes = [
  { path: '', component: DefaultComponent },
  {
    path: '',
    children: [
      { path: ':dlr/:id/:ref', component: HomeComponent },
      { path: 'error', component: ErrorPageComponent },
    ]
  },
  { path: '**', redirectTo: '', pathMatch: 'full' }

];

现在我在HomeComponent中,想转到错误页面。

this.router.navigate(['/еrror'])这将我引向DefaultComponent

angular angular-ui-router angular2-routing angular8 router
1个回答
0
投票
 this.router.navigate(['/error'], { relativeTo: this.activatedRoute });

添加relativeTo对我有用。

© www.soinside.com 2019 - 2024. All rights reserved.