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

前端 未结 11 1996
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:37

    You can navigate to your parent root like this

    this.router.navigate(['.'], { relativeTo: this.activeRoute.parent });
    

    You will need to inject the current active Route in the constructor

    constructor(
        private router: Router,
        private activeRoute: ActivatedRoute) {
    
      }
    

提交回复
热议问题