Skip to content

Instantly share code, notes, and snippets.

@Himenon
Created November 29, 2019 01:51
Show Gist options
  • Save Himenon/aa6b6e7ce72c2dbbc1cb2cbeb5996bfb to your computer and use it in GitHub Desktop.
Save Himenon/aa6b6e7ce72c2dbbc1cb2cbeb5996bfb to your computer and use it in GitHub Desktop.
特定のqueryパラメーターを更新する関数
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