How to Remove a Query String From a URL in JavaScript
Serhii Shramko /
To remove query parameters from a URL in JavaScript, you can use the following function:
function removeQueryParams(inputUrl: string): string {
const url = new URL(inputUrl);
url.search = '';
return url.toString();
}
removeQueryParams('https://www.example.com/page?param1=value1¶m2=value2');
// Output: https://www.example.com/page