Created
March 15, 2023 09:21
-
-
Save Steven24K/9243479ac5283da272d3e5da2f62541f to your computer and use it in GitHub Desktop.
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
function getUrlParam(key: string): string { | |
const urlParams = new URLSearchParams(window.location.search); | |
return urlParams.get(key) ?? ""; | |
} | |
function addUrlParam(key: string, value: string): void { | |
const url = new URL(window.location.href); | |
url.searchParams.set(key, value); | |
const newUrl = url.href; | |
window.history.pushState({ path: newUrl }, "", newUrl); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment