Created
November 29, 2019 01:51
-
-
Save Himenon/aa6b6e7ce72c2dbbc1cb2cbeb5996bfb to your computer and use it in GitHub Desktop.
特定のqueryパラメーターを更新する関数
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 updateQueryStringParameter = (key: string, value: string): void => { | |
const searchParams = new URLSearchParams(window.location.search); | |
const params = {}; | |
searchParams.forEach((v, k) => { | |
params[k] = v; | |
}); | |
if (value === "") { | |
delete params[key]; | |
} else { | |
params[key] = value; | |
} | |
history.replaceState(null, document.title, `?${queryaprams.stringify(params)}`); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment