Remove a parameter from queryParams angular 2

前端 未结 9 1223
半阙折子戏
半阙折子戏 2021-01-31 09:42

I navigate to a certain page in my app with a query parameter. After I get the parameter from the URL I want to delete it, ideally I would have this:



        
9条回答
  •  梦毁少年i
    2021-01-31 10:32

    I was looking for answer like this when I wanted to remove access_token parameter from url. If you just want remove one parameter and retain the other parameters.

    setTimeout(() => {
      let urlWithoutAccessToken = this.router.url.replace(new RegExp('.access_token=' + idToken), '');
      this.router.navigateByUrl(urlWithoutAccessToken);
    }, 0);
    

    The setTimeout was needed for some reason, the navigateByUrl didn't work without it.

提交回复
热议问题