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

前端 未结 11 2014
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:30

    This seems to work for me as of Spring 2017:

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

    Where your component ctor accepts ActivatedRoute and Router, imported as follows:

    import { ActivatedRoute, Router } from '@angular/router';

提交回复
热议问题