【问题标题】:Navigate using url and ../ in Angular 5在 Angular 5 中使用 url 和 ../ 进行导航
【发布时间】:2018-10-21 23:19:28
【问题描述】:

我的 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

【问题讨论】:

标签: angular navigation router


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2012-12-25
    • 2018-05-19
    • 2015-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-08
    • 1970-01-01
    相关资源
    最近更新 更多