我有如下所示的路由:
const routes: Routes = [
{ path: '', redirectTo: '/login', pathMatch: 'full' },
{ path: 'login', component: LoginComponent },
{ path: 'home', component: HomeComponent,
children:[
{ path: '', redirectTo: 'cat', pathMatch: 'full' },
{ path: 'cat', component: CatComponent},
{ path: 'dog', component: DogComponent},
{ path: 'vet/:id', component: VetComponent,
children:[
{ path: '', redirectTo: 'hospital', pathMatch: 'full' },
{ path: 'hospital', component: HospitalComponent},
{ path: 'clinic', component: ClinicComponent}
]}
]},
{ path: '**', redirectTo: '/login', pathMatch: 'full' },
];然后,我尝试访问诊所路径,因此:
/home/vet/9999/clinic因此,我尝试了以下方法:
this.router.navigate(['/home/vet/clinic', 9999]);
this.router.navigate(['/home/vet/:id/clinic', 9999]);但是我一直被重定向到登录页面。
我需要能够转到诊所页面,并且还可以访问id变量。我不确定我做错了什么。
发布于 2017-11-08 03:45:11
我找到了答案。当你调用它的时候,它需要看起来像这样:
this.router.navigate(['/home/vet', 9999, 'clinic']);而不是
this.router.navigate(['/home/vet/clinic', 9999]);https://stackoverflow.com/questions/47166102
复制相似问题