Last active
October 31, 2025 16:00
-
-
Save caseywatts/f587bcd4a5337cb5c01b054e67270588 to your computer and use it in GitHub Desktop.
Get/Set Query Parameters
This file contains hidden or 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
| // reading from the search parameter | |
| console.log(params.q); | |
| // writing to the URL in the navigation bar | |
| params.q = "new query"; |
This file contains hidden or 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 params = new Proxy(new URL(window.location), { | |
| get: (url, prop) => url.searchParams.get(prop), | |
| set: (url, prop, value) => { | |
| url.searchParams.set(prop, value); | |
| window.history.replaceState({}, "", url); | |
| }, | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment