---
name: "up.history.config"
area: "API"
kind: "Configuration object"
parent: "up.history module"
url: "https://unpoly.com/api/up.history.config"
---
<nav aria-label="Unpoly docs">[All docs](https://unpoly.com/index.md) · [up.history module](https://unpoly.com/api/up.history.md)</nav>

# up.history.config

Configures behavior when the user goes back or forward in browser history.

---

## Value {#value}

### History {#value-history}

#### [config.restoreTargets=['body']] {#config.restoreTargets}

(optional)

A list of possible CSS selectors to [replace](https://unpoly.com/api/up.render.md) when the user [goes back or forward in history](https://unpoly.com/learn/restoring-history.md).

If more than one target is configured, the first selector matching both the current page and server response will be updated.

If nothing is configured, the `<body>` element will be replaced.

Type: [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)

#### [config.enabled=true] {#config.enabled}

(optional)

Configures which aspects of history [fragment updates](https://unpoly.com/api/up.render.md) can [update](https://unpoly.com/learn/updating-history.md).

If set to `true`, Unpoly may change the browser URL, the window title, [meta tags](https://unpoly.com/learn/updating-history.md#history-state) and the `<html>` element's `[lang]` attribute.

If set to `false`, Unpoly will never change any of these.

To only update some aspects, set an array of the aspects Unpoly may update:

| Aspect | Updates |
| --- | --- |
| `'location'` | The browser URL and history entries. |
| `'title'` | The window title. |
| `'metaTags'` | [Meta tags](https://unpoly.com/api/up-meta.md) in the `<head>`. |
| `'lang'` | The `<html>` element's `[lang]` attribute. |

For example, this configuration never changes the browser URL, but still updates the `[lang]` attribute when the user switches to another language:

```js
up.history.config.enabled = ['lang']
```

An empty array has the same effect as `false`.

Render options can only narrow this setting, never update an aspect that it excludes. An overlay without [visible history](https://unpoly.com/learn/history-in-overlays.md) never updates history, regardless of this setting.

See [Turning off history aspects](https://unpoly.com/learn/updating-history.md#disabling) for the consequences of excluding an aspect.

Type: boolean | [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<string>

### Meta tags {#value-meta-tags}

#### [config.updateMetaTags] {#config.updateMetaTags}

(optional)

Configures whether [history changes](https://unpoly.com/learn/updating-history.md) update [meta tags](https://unpoly.com/learn/updating-history.md#history-state) in addition to the document's title and URL.

Type: boolean

#### [config.metaTagSelectors] {#config.metaTagSelectors}

(optional)

An array of CSS selectors matching default [meta tags](https://unpoly.com/api/up-meta.md) that are updated during [history changes](https://unpoly.com/learn/updating-history.md).

By default, the following elements are matched:

- All `meta` elements
- A `link[rel="alternate"]` element
- A `link[rel="canonical"]` element
- A `link[rel="icon"]` element
- [JSON-LD](https://json-ld.org/) annotations

You can [include additional elements](https://unpoly.com/api/up-meta.md#including-meta-tags) by assigning an [`[up-meta]`](https://unpoly.com/api/up-meta.md) attribute or by pushing their selector into this configuration array.

Only elements in the `<head>` can be matched. Elements in the `<body>` are never considered, even if they match one of the configured selectors.

Type: [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<string>

#### [config.noMetaTagSelectors] {#config.noMetaTagSelectors}

(optional)

Exceptions to `up.history.config.metaTagSelectors`.

Matching elements will _not_ be considered [meta tags](https://unpoly.com/api/up-meta.md) even if they match `up.history.config.metaTagSelectors`.

Type: [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<string>

