【发布时间】:2019-04-16 10:29:24
【问题描述】:
我有以下路线-
const routes: Routes = [
{
path: '',
component: ParentComponent,
children: [
{
path: ':id',
component: ChildComponent,
},
]
}
];
在父级的构造函数中,我想导航到某个 id,例如“test”。 我试过这个-
constructor(private router: Router) {
this.router.navigate(['child']);
}
还有这个-
constructor(private router: Router) {
this.router.navigate(['/child']);
}
还有这个-
constructor(private router: Router) {
this.router.navigate(['./child']);
}
还有这个——
constructor(private router: Router) {
this.router.navigate(['../child']);
}
我的网址是 - http://localhost:4200/parent。
但是所有这些选项我都去http://localhost:4200/child而不是http://localhost:4200/parent/child
知道为什么吗?我怎样才能使它相对于父母?
【问题讨论】:
标签: javascript angular typescript routes