---
area: "Learn"
parent: "Learn"
url: "https://unpoly.com/learn/history"
---
<nav aria-label="Unpoly docs">[All docs](https://unpoly.com/index.md) · [Learn](https://unpoly.com/learn.md)</nav>

# History

Unpoly keeps the browser history working while it updates fragments. When a link or form changes the page's main fragment, the address bar and window title change as they would for a full page load, and the Back button brings the earlier page back.

<nav aria-label="Contents">

#### Contents

- [Updating the address bar](#updating-the-address-bar)
- [Restoring the previous page](#restoring-the-previous-page)
- [Tracking page views](#tracking-page-views)
- [See also](#see-also)

</nav>

## Updating the address bar {#updating-the-address-bar}

An update counts as a page change when it swaps the page's [main fragment](https://unpoly.com/api/main.md). Only then does Unpoly push a history entry, so users can bookmark, share and reload each URL as usual.

Smaller updates leave history alone. Paginating comments doesn't add a history entry, so the Back button skips straight to the previous page:

```html
<a href="/comments?page=2" up-target="#comments">Next page</a>
```

To override this default for a link or form, set `[up-history=true]` or `[up-history=false]`.

<nav aria-label="Read more">

- [More: Updating history](https://unpoly.com/learn/updating-history.md)

</nav>

## Restoring the previous page {#restoring-the-previous-page}

When the user presses the Back button, Unpoly fetches the earlier URL and renders its `<body>` into the current page. Scroll positions and focus are restored to where the user left them. Since responses are [cached](https://unpoly.com/learn/caching.md), going back is usually instant.

To keep parts of your layout alive, restore a smaller fragment:

```js
up.history.config.restoreTargets = ['.content', 'body']
```

To customize the render pass, or to restore the page with your own code, listen to [`up:location:restore`](https://unpoly.com/api/up:location:restore.md). To offer a _Back_ link inside the page, use an [`[up-back]`](https://unpoly.com/learn/restoring-history.md#back-link) attribute.

<nav aria-label="Read more">

- [More: Restoring history](https://unpoly.com/learn/restoring-history.md)

</nav>

## Tracking page views {#tracking-page-views}

Analytics tools count a page view on every page load. With Unpoly the page loads once, so track a view whenever the location changes:

```js
up.on('up:location:changed', function(event) {
  trackPageView(event.location)
})
```

One listener covers every way the location can change: followed links, redirecting forms and the Back button.

<nav aria-label="Read more">

- [More: Tracking page views](https://unpoly.com/learn/tracking-page-views.md)

</nav>

## See also {#see-also}

To control whether an overlay's URL shows in the address bar, see [History in overlays](https://unpoly.com/learn/history-in-overlays.md).

<nav aria-label="In this chapter">

## In this chapter {#children-index-title}

- [Updating history](https://unpoly.com/learn/updating-history.md)
- [Restoring history](https://unpoly.com/learn/restoring-history.md)
- [Tracking page views](https://unpoly.com/learn/tracking-page-views.md)

</nav>

<nav aria-label="Reading order">

- [Previous: Notification flashes](https://unpoly.com/learn/flashes.md)
- [Next: Updating history](https://unpoly.com/learn/updating-history.md)

</nav>

