在Angular 5中使用url和../导航

时间:2018-10-21 10:44:26

标签: angular navigation router

我的html中有这个

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

在我的ts里:

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

我现在站在以下网址中:http://localhost:4200/profile/username/photos

我希望网址变为:http://localhost:4200/profile/username/my-albums

但是结果:http://localhost:4200/my-albums

1 个答案:

答案 0 :(得分:0)

在链接参数数组之后,将一个具有relativeTo属性设置的对象添加到ActivatedRoute。然后,路由器根据活动路由的位置计算目标URL。您可以尝试这样:

this.router.navigate(['../my-albums/' + post_id], { relativeTo: this.route });
相关问题