Skip to content

Instantly share code, notes, and snippets.

@ashaffah
Created May 11, 2026 08:33
Show Gist options
  • Select an option

  • Save ashaffah/d8a75c016c4cf7368c5c0ba7d95b4ad2 to your computer and use it in GitHub Desktop.

Select an option

Save ashaffah/d8a75c016c4cf7368c5c0ba7d95b4ad2 to your computer and use it in GitHub Desktop.
url resolver
(() => {
const allowedParams = ["id", "page", "tab"];
const url = new URL(window.location);
const params = url.searchParams;
const currentKeys = Array.from(params.keys());
currentKeys.forEach((key) => {
if (!allowedParams.includes(key)) {
params.delete(key);
}
});
window.history.replaceState({}, "", url);
})();
(() => {
const url = new URL(window.location);
for (const key of [...url.searchParams.keys()]) {
if (!["id", "page", "tab"].includes(key)) url.searchParams.delete(key);
}
window.history.replaceState({}, "", url);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment