如何在不刷新角度 8 的页面的情况下更改 url 的值

How to change the value of the url without refreshing the page in angular8

我已经使用 window.open 在新选项卡中打开页面,在新选项卡中,在主屏幕上我有一个编辑和查看选项,所以如果我在 url 我传递了 1,点击编辑我传递了 2,所以我传递了 3 个值,有 2 个代码。 现在,当我从主页面点击查看按钮时,我得到 url 这样的:

http://localhost:4200/data?dt=1211-1211-1

因此,在视图中我有一个“编辑”按钮,它可以启用所有字段进行编辑,所以在这里我希望我的 url 成为

http://localhost:4200/data?dt=1211-1211-2,

因此,它将处于编辑模式。 我已经使用激活的路由器从 url 从主页到新选项卡

获取值
 let url = this.route.snapshot.queryParams.dt.split("-");
    this.gp= url[0];
    this.ap = url[1];
    this.mode = url[2];

您可以使用新的查询参数导航到当前路由,这不会重新加载您的页面,但会更新查询参数

editMode(){
const queryParams = this.gp.toString() + this.ap.toString() + '2';    
this.router.navigate(
        [], 
        {
          relativeTo: this.route,
          queryParams: queryParams,
          queryParamsHandling: 'merge'
        });
}