Issue
How would I remove a query parameter from the URL? For example from www.expample.com/home?id=123&pos=sd&sd=iii
to www.expample.com/home?id=123&sd=iii
EDIT: This is my version:
this.activatedRoute.queryParams.subscribe(c => {
const params = Object.assign({}, c);
delete params.dapp;
this.router.navigate([], { relativeTo: this.activatedRoute, queryParams: params });
}).unsubscribe();
Solution
You can remove a query parameter by using the merge
option of queryParamsHandling
and passing in null
for any params you wish to remove.
// Remove query params
this.router.navigate([], {
queryParams: {
'yourParamName': null,
'youCanRemoveMultiple': null,
},
queryParamsHandling: 'merge'
})
This option is simpler and requires less work to ensure you are not removing other params. You also do not need to worry about cleaning up an observable subscription when your component is destroyed.
Answered By - epelc
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.