Remove a parameter from queryParams angular 2

前端 未结 9 1265
半阙折子戏
半阙折子戏 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条回答
  •  梦谈多话
    2021-01-31 10:29

    I would suggest this way that is compatible with all routing strategies of Angular X:

        this.route.queryParams.subscribe(params => {
            let token = params['jwt'];
            if (token) {
                this.cache.set({t: 't'}, token);
                window.location.href = this.router.url.split('?')[0];
            }
        });
    

提交回复
热议问题