我正在尝试重定向到这样的另一个组件:
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
this.router.navigate(['/error'], { relativeTo: this.activatedRoute });
添加relativeTo对我有用。