Created
June 7, 2021 12:42
-
-
Save paulmwatson/828564e177e33420e6e69ce314e8deb3 to your computer and use it in GitHub Desktop.
Manipulating the query string with URLSearchParams
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const url = 'https://host.test/path/here.filetype?query=string&more=params#anchor'; | |
let newUrl = new URL(url); | |
let params = new URLSearchParams(newUrl.search); | |
params.set('query', `${params.get('query')}-changed`); | |
params.delete('more'); | |
params.set('new', 'param'); | |
newUrl.search = params; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment