且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Angular2,如何在路由器导航上清除URL查询参数

更新时间:2022-06-14 23:11:36

正如DeborahK指出的那样,当我导航到this.router.url时,该URL已经嵌入了url参数.为了解决这个问题,我从字符串中剥离了URL的参数,然后使用navigationByUrl跳到那里.

As DeborahK pointed out, when I was navigating to this.router.url, that URL already had the url params embedded. To solve I stripped the params off the URL as a string, and then used navigateByUrl to jump there.

let url: string = this.router.url.substring(0, this.router.url.indexOf("?"));
this.router.navigateByUrl(url);