How do I navigate to a parent route from a child route?

前端 未结 11 1990
Happy的楠姐
Happy的楠姐 2020-11-29 19:04

My problem is quite classic. I have a private part of an application which is behind a login form. When the login is successful, it goes to a child route for th

11条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-29 19:35

    constructor(private router: Router) {}
    
    navigateOnParent() {
      this.router.navigate(['../some-path-on-parent']);
    }
    

    The router supports

    • absolute paths /xxx - started on the router of the root component
    • relative paths xxx - started on the router of the current component
    • relative paths ../xxx - started on the parent router of the current component

提交回复
热议问题