Skip to content

Instantly share code, notes, and snippets.

@caseywatts
Last active October 31, 2025 16:00
Show Gist options
  • Select an option

  • Save caseywatts/f587bcd4a5337cb5c01b054e67270588 to your computer and use it in GitHub Desktop.

Select an option

Save caseywatts/f587bcd4a5337cb5c01b054e67270588 to your computer and use it in GitHub Desktop.
Get/Set Query Parameters
// reading from the search parameter
console.log(params.q);
// writing to the URL in the navigation bar
params.q = "new query";
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