(
params: Record<string, string | null>,
options: { replace?: boolean } = {},
)
| 7 | * @returns {URLSearchParams} - The updated search parameters. |
| 8 | */ |
| 9 | export function setGlobalSearchParams( |
| 10 | params: Record<string, string | null>, |
| 11 | options: { replace?: boolean } = {}, |
| 12 | ) { |
| 13 | const searchParams = new URLSearchParams(window.location.search) |
| 14 | for (const [key, value] of Object.entries(params)) { |
| 15 | if (!value) searchParams.delete(key) |
| 16 | else searchParams.set(key, value) |
| 17 | } |
| 18 | const newUrl = [window.location.pathname, searchParams.toString()] |
| 19 | .filter(Boolean) |
| 20 | .join('?') |
| 21 | if (options.replace) { |
| 22 | window.history.replaceState({}, '', newUrl) |
| 23 | } else { |
| 24 | window.history.pushState({}, '', newUrl) |
| 25 | } |
| 26 | return searchParams |
| 27 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…