Angular2 cannot move relative to parent route

I am using angular2 cli.

test related to relative problems:

routing configuration:

{
    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 the component check-company-home

goIdPage(){
    this.router.navigate(['22'], { relativeTo: this.route });
  }

can move from "/ company" to "/ company / 22"

In the check-company-detail component:

goBack(){
    this.router.navigate(['../'], { relativeTo: this.route });
  }

But can’t move in the form "/ company / 22" to "/ company",

why?

+5
source share
2 answers

Try using only one point:

goBack(){
    this.router.navigate(['./'], { relativeTo: this.route });
}
+1
source

This works when I install relativeTo: this.route.parentand use one point ['./'].

goBack(){
    this.router.navigate(['./'], { relativeTo: this.route.parent });
}
0
source

Source: https://habr.com/ru/post/1659694/


All Articles