CKTIS / JavaScript
history.replaceState — update the current history entry
history.replaceState updates the state and optionally the URL of the current history entry without reloading the page. It does not add an entry, so it creates no additional Back-button step.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
history.replaceState(data, unused)
history.replaceState(data, unused, url)history.replaceState(data, unused, url) replaces the current entry's state; history.pushState adds an entry. This is a browser API defined by HTML, not a feature of a particular ECMAScript edition. Having Node 24 does not establish browser availability.
Pass "" as the required historical unused argument; it does not set the title. Omitting url preserves the address. The method returns undefined. It does not reload the document or itself fire popstate or hashchange.
data undergoes structured cloning for storage, not JSON serialization. Read the stored value through history.state; subsequently changing the input object does not change the stored value. Functions and DOM nodes cannot be stored this way and cause DataCloneError.
The URL-rewriting rules compare the proposed URL with the document's current URL, not with the document's origin. For example, a document at about:blank can change its URL fragment even if it inherits its origin. A disallowed URL, a document that is not fully active, or call-frequency restrictions can cause SecurityError. Use this method to correct the current view, not to create a new navigation step.
Examples
(() => {
const previousState = history.state;
const previousURL = location.href;
const previousLength = history.length;
const data = { tab: "details" };
const url = new URL(location.href);
url.hash = "details";
try {
history.replaceState(data, "", url.href);
data.tab = "changed";
console.log(history.state.tab);
console.log(location.hash);
console.log(history.length === previousLength);
} finally {
history.replaceState(previousState, "", previousURL);
}
})();Result
details #details true
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.