Navigate relative with Angular 2 Router (Version 3)

前端 未结 4 1474
野性不改
野性不改 2021-02-01 12:31

How to navigate relative from /questions/123/step1 to /questions/123/step2 within a component using Router without string concatenation an

4条回答
  •  无人共我
    2021-02-01 12:36

    Note: the routes are case sensitive so make sure you match the casing across

    This worked for me for Angular 8:
    From the parent component / page, to navigate to the sub page using typescript:

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

    My router in the parent's module looks like this:

    const routes: Routes = [
      {
        path: '',
        component: MyPage,
        children: [
          { path: 'subPage', component: subPageComponent}
        ]
      }
    ];
    

    And on the parent's html page use the following to navigate using a link:

    Sub Page Link
    
    

提交回复
热议问题