How to add a new parameter to the URL without affecting the current working

 newUrl = window.location.href + ‘?/toggle=enprimeur’;
window.history.pushState({ path: newUrl }, ”, newUrl);

This code replaces the last segment of the current URL with the string ‘retail’ and updates the browser’s history state with the new URL. Thus it will not cause any issues in the current working. Otherwise we will get “page not found” error after adding a segment to the current URL.

window.history.pushState Above method allows you to update the browser’s history state without actually reloading the page. This can be useful for building single-page applications or for updating the URL to reflect changes in the application state.While the URL is updated, the page content remains the same until you manually update it.

Leave a comment

Your email address will not be published. Required fields are marked *