change window location without refresh code example
Example 1: javascript change url
history.pushState({}, null, newUrl);
Example 2: change href without reloading page js
// Current URL: https://my-website.com/page_a
const nextURL = 'https://my-website.com/page_b';
const nextTitle = 'My new page title';
const nextState = { additionalInformation: 'Updated the URL with JS' };
// This will create a new entry in the browser's history, without reloading
window.history.pushState(nextState, nextTitle, nextURL);
// This will replace the current entry in the browser's history, without reloading
window.history.replaceState(nextState, nextTitle, nextURL)
Example 3: how to set window location search without reload
window.history.replaceState( {} , title, new_URL );
Example 4: how to set window location search without reload
window.history.pushState('', 'New Page Title', '/new-url.php');