mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-05-12 13:49:22 -05:00
19 lines
449 B
TypeScript
19 lines
449 B
TypeScript
export const setSearchParams = (key: string, value: string | undefined) => {
|
|
const url = new URL(window.location.href);
|
|
const params = new URLSearchParams(url.search);
|
|
|
|
if (!value) {
|
|
params.delete(key);
|
|
} else {
|
|
params.set(key, value); // encodeURIComponent(value)
|
|
}
|
|
|
|
history.replaceState(
|
|
{},
|
|
"",
|
|
`${window.location.pathname}${
|
|
Array.from(params.entries()).length ? "?" : ""
|
|
}${params.toString()}`
|
|
);
|
|
};
|