# navigation

> The `navigation` JS object of the Navigation API allows initiating, intercepting and managing browser navigations.

## How do I use the Navigation API for client-side routing?

The global object of the Navigation API for handling navigation in single-page applications. It lets apps intercept navigations with the `navigate` event, read the app's history entries and replace many uses of the `history` object.

- Topic: Navigation in Browser
- Type: object
- Browser support: Chrome 102+, Chrome Android 102+, Edge 102+, Firefox 147+, Firefox Android 147+, Safari 26.2+, Safari iOS 26.2+

## Example

Wrong:

```js
document.addEventListener('click', (e) => {
  const a = e.target.closest('a');
  if (!a) return;
  e.preventDefault();
  history.pushState({}, '', a.href);
  render(a.href);
});
```

Right:

```js
navigation.addEventListener('navigate', (event) => {
  if (!event.canIntercept || event.hashChange || event.downloadRequest) return;
  const url = new URL(event.destination.url);
  event.intercept({ handler: () => render(url.pathname) });
});
```

One `navigate` handler covers links, forms and back or forward, so routing needs no click listeners or `pushState()`.

## Common mistakes

- Calling `intercept()` for a cross-origin navigation, which throws.

## Key points

- The `navigate` handler checks `event.canIntercept` before calling `event.intercept()`.
- Downloads and hash-only changes are skipped by checking `downloadRequest` and `hashChange`.
- Routing uses `event.intercept()` instead of click handlers on links plus `history.pushState()`.
- Browsers without the API fall back to normal page loads or the History API.

## Interview questions

### Navigation API vs History API: which should I use?

Use the Navigation API where it is supported, since one `navigate` event covers every navigation. Keep the History API as a fallback.

### Does navigation.navigate() reload the page?

Not if a `navigate` handler intercepts it. Without interception, it performs a normal navigation.

### How do I list history entries with the Navigation API?

Call `navigation.entries()`. It returns the same-origin entries of the current tab.

## Related cards

- [history](https://wonderium.dev/js/history.md)
- [location](https://wonderium.dev/js/location.md)
- [SPA](https://wonderium.dev/web/spa.md)
- [Router](https://wonderium.dev/web/router.md)
- [document.startViewTransition()](https://wonderium.dev/js/start-view-transition.md)

---

- Level: [JavaScript](https://wonderium.dev/js.md)
- HTML version: https://wonderium.dev/js/navigation
- Last updated: 2026-11-25
