GO-Ve01
ServicesDevelopersBooksDictionaryPapersWikidataEncyclopediaSearchBabelCareersDeck

NavigationHistoryEntry: getState() method

Navigation API

Navigation API

The **`getState()`** method of the NavigationHistoryEntry interface returns a clone of the developer-supplied state associated with this history entry.

## Syntax

```js-nolint
getState()
```

### Parameters

None.

### Return value

A value representing the state. This can be any [structured-cloneable](/docs/Web/API/Web_Workers_API/Structured_clone_algorithm) data type.

If no state is defined or if current document is not fully active, it returns `undefined`.

### Exceptions

None.

## Examples

```js
async function handleReload() {
// Update existing state via reload()
await navigation.reload({
state: { ...navigation.currentEntry.getState(), newState: 3 },
});

// Print current state to the console
const current = navigation.currentEntry;
console.log(current.getState());
}
```

## Specifications

## Browser compatibility

## See also

- [Modern client-side routing: the Navigation API](https://developer.chrome.com/docs/web-platform/navigation-api/)
- [Navigation API explainer](https://github.com/WICG/navigation-api/blob/main/README.md)
- Methods that allow state to be updated — Navigation.navigate(), Navigation.reload(), and Navigation.updateCurrentEntry()

source: MDN Web Docs mirror · page

Cite this

"NavigationHistoryEntry: getState() method". MDN Web Docs. CC BY-SA 2.5 (MDN). https://developer.mozilla.org/en-US/docs/Web/API/NavigationHistoryEntry/getState

JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy

Save to pass ·