As 'UrlQueryParameterCollection'UrlQueryParameterCollection is deprecated., I suggest to use the URLSearchParams browser API instead.
Here is my code to get value of search parameter:
const url = new URL(window.location.href); const params = new URLSearchParams(url.search); let searchParam: string; params.has('search') ? searchParam = params.get("search") : searchParam = ""; Here is my code to delete search parameter and update URL:
const url = new URL(window.location.href); const params = new URLSearchParams(url.search); if (params.has('search')) { params.delete('search'); window.history.replaceState({}, '', `${location.pathname}?${params}`); }