Roadmap to becoming a developer in 2022
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
775 B

export function getUrlParams() {
const params = new URLSearchParams(window.location.search);
const paramsObj: Record<string, any> = {};
for (const [key, value] of params.entries()) {
paramsObj[key] = value;
}
return paramsObj;
}
export function deleteUrlParam(key: string) {
const url = new URL(window.location.href);
if (!url.searchParams.has(key)) {
return;
}
url.searchParams.delete(key);
window.history.pushState(null, '', url.toString());
}
export function setUrlParams(params: Record<string, string>) {
const url = new URL(window.location.href);
for (const [key, value] of Object.entries(params)) {
url.searchParams.delete(key);
url.searchParams.set(key, value);
}
window.history.pushState(null, '', url.toString());
}