Blogs Tech stuff and many more...
If we want to dynamically add or change query string, URL API can be used as shown below
const url = new URL(location.href);
url.searchParams.set('queryStringKey', 'queryStringValue');
Cheers
Samitha