Reputation: 5906
I use angular2 cli .
test navigating relative met problems:
routing config:
{
path: '',
component: CheckCompanyComponent,
children:[
{
path:'',
loadChildren: 'app/components/company/check-company-home/check-company-home.module#CheckCompanyHomeModule'
},
{
path:':id',
loadChildren: 'app/components/company/check-company-detail/check-company-detail.module#CheckCompanyDetailModule'
}
]
}
In check-company-home component
goIdPage(){
this.router.navigate(['22'], { relativeTo: this.route });
}
can navigate from "/company" to "/company/22"
In check-company-detail component:
goBack(){
this.router.navigate(['../'], { relativeTo: this.route });
}
But can't navigate form "/company/22" to "/company",
why?
Upvotes: 9
Views: 10154
Reputation: 591
It works when I set relativeTo: this.route.parent
and use single dot ['./']
.
goBack(){
this.router.navigate(['./'], { relativeTo: this.route.parent });
}
Upvotes: 8
Reputation: 8613
Try it with only one dot:
goBack(){
this.router.navigate(['./'], { relativeTo: this.route });
}
Upvotes: 2