computer-scienceangular-roadmapbackend-roadmapblockchain-roadmapdba-roadmapdeveloper-roadmapdevops-roadmapfrontend-roadmapgo-roadmaphactoberfestjava-roadmapjavascript-roadmapnodejs-roadmappython-roadmapqa-roadmapreact-roadmaproadmapstudy-planvue-roadmapweb3-roadmap
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.
42 lines
946 B
42 lines
946 B
export function getUrlParams() { |
|
if (typeof window === 'undefined') { |
|
return {}; |
|
} |
|
|
|
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) { |
|
if (typeof window === 'undefined') { |
|
return; |
|
} |
|
|
|
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>) { |
|
if (typeof window === 'undefined') { |
|
return; |
|
} |
|
|
|
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()); |
|
}
|
|
|