Thursday, April 26, 2018

I used relativeTo in Angular routing yesterday for the first time.

I was able to refactor this...

this.router.navigate(['/foo/bar/baz/', qux]);


...into this:

this.router.navigate(['../', qux], {
   relativeTo: this.activatedRoute


My constructor of my component looks like this:

constructor(private activatedRoute: ActivatedRoute, private router: Router) {


I have this import up top.

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

No comments:

Post a Comment