0

I have this in my html:

(click)="openAlbum($event, album.post_id)"

And in my ts:

 openAlbum(event, post_id) {
            this.router.navigate(['../my-albums/' + post_id]);
    }

I'm standing now in this url: http://localhost:4200/profile/username/photos

I expected the url become: http://localhost:4200/profile/username/my-albums

But the result: http://localhost:4200/my-albums

Marvin Ericson
  • 239
  • 2
  • 7
  • 20
  • why don't you give full url in router navigate? like `this.router.navigate(['profile/username/my-albums/' + post_id]);` – Ebin Manuval Oct 21 '18 at 10:48
  • 1
    Possible duplicate of [Navigate relative with Angular 2 Router (Version 3)](https://stackoverflow.com/questions/39124906/navigate-relative-with-angular-2-router-version-3) – Jota.Toledo Oct 21 '18 at 14:59

1 Answers1

0

After the link parameters array, add an object with a relativeTo property set to the ActivatedRoute. The router then calculates the target URL based on the active route's location. You can try like this:

this.router.navigate(['../my-albums/' + post_id], { relativeTo: this.route });
Linh Pham
  • 11
  • 3