history.pushState
Pushes the given data onto the session history stack with the specified title and, if provided, URL
Syntax
history.pushState(state, unused, url?)Parameters
| Parameter | Type | Description |
|---|---|---|
| state | any | A serializable object associated with the new history entry |
| unused | string | This parameter exists for historical reasons and cannot be omitted |
| url | string | URL | The new history entry's URL |
Return Value
undefined
Examples
history.pushState({ page: 'about' }, '', '/about')
console.log(history.state) // { page: 'about' }function navigate(path: string, state = {}) {
history.pushState(state, '', path)
renderRoute(path)
}const params = new URLSearchParams({ q: 'search', page: '2' })
history.pushState(null, '', `?${params}`)
console.log(window.location.search)Understanding history.pushState
The history.pushState method in JavaScript pushes the given data onto the session history stack with the specified title and, if provided, URL. It belongs to the History object and is one of the most widely used methods for working with history values in modern JavaScript and TypeScript applications.
The method signature is history.pushState(state, unused, url?). It accepts 3 parameters: state, unused, url. When called, it returns undefined. Understanding when and how to use pushState() helps you write more expressive, readable code.
Common use cases for history.pushState include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like history-replacestate, history-back, history-go, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for history.pushState is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.
Browser Compatibility
Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.
Related Methods
history.replaceStateModifies the current history entry, replacing it with the state, title, and URL passed in the method parameters
history.backCauses the browser to move back one page in the session history, equivalent to clicking the browser's back button
history.goLoads a page from the session history, identified by its relative location to the current page
More History Methods
Other methods in the History object
Related Tools
More History Methods
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.