e01.org

NavigationHistoryEntry

Navigation API

Navigation API

The **`NavigationHistoryEntry`** interface of the Navigation API represents a single navigation history entry.

These objects are commonly accessed via the Navigation.currentEntry property and Navigation.entries() method.

The Navigation API only exposes history entries created in the current browsing context that have the same origin as the current page (e.g., not navigations inside embedded iframes, or cross-origin navigations), providing an accurate list of all previous history entries just for your app. This makes traversing the history a much less fragile proposition than with the older History API.

## Instance properties

_Inherits properties from its parent, EventTarget._

- id
- : Returns the `id` of the history entry. This is a unique, UA-generated value that always represents a specific history entry, useful to correlate it with an external resource such as a storage cache.
- index
- : Returns the index of the history entry in the history entries list (that is, the list returned by Navigation.entries()), or `-1` if the entry does not appear in the list.
- key
- : Returns the `key` of the history entry. This is a unique, UA-generated value that represents the history entry's slot in the entries list rather than the entry itself. It is used to navigate that particular slot via Navigation.traverseTo(). The `key` will be reused by other entries that replace the entry in the list (that is, if the NavigateEvent.navigationType is `replace`).
- sameDocument
- : Returns `true` if this history entry is for the same `document` as the current Document value, or `false` otherwise.
- url
- : Returns the absolute URL of this history entry. If the entry corresponds to a different document than the current one (like `sameDocument` property is `false`), and that document was fetched with a Referrer-Policy header set to `no-referrer` or `origin`, the property returns `null`.

## Instance methods

_Inherits methods from its parent, EventTarget._

- getState()
- : Returns a clone of the available state associated with this history entry.

## Events

- dispose
- : Fires when the entry is no longer part of the history entry list.

## Examples

```js
function initHomeBtn() {
// Get the key of the first loaded entry
// so the user can always go back to this view.
const { key } = navigation.currentEntry;
backToHomeButton.onclick = () => {
navigation.traverseTo(key);
};
}
// Intercept navigate events, such as link clicks, and
// replace them with single-page navigations
navigation.addEventListener("navigate", (event) => {
event.intercept({
async handler() {
// Navigate to a different view,
// but the "home" button will always work.
},
});
});
```

## 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)
- [Navigation API live demo](https://mdn.github.io/dom-examples/navigation-api/) ([view demo source](https://github.com/mdn/dom-examples/tree/main/navigation-api))

source: MDN Web Docs mirror · page

Cite this

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

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

Save to pass ·