# history-events

> Adds missing window.history events onpushstate, onreplacestate and onchangestate.

Latest version **1.0.4** (published 2015-08-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install history-events
pnpm add history-events
yarn add history-events
bun add history-events
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2015-08-10 |
| First published | 2015-08-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/history-events) |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 17 |
| Author | Xpepermint |
| Maintainers | xpepermint |
| Keywords | pushstate, popstate, replacestate, browser, history, events, window, document, html5, transition, url, location, href, router, back, forward, goto, link, react |

## Links

- npm: https://www.npmjs.com/package/history-events
- Repository: https://github.com/xpepermint/history-events
- Homepage: https://github.com/xpepermint/history-events#readme
- Issues: https://github.com/xpepermint/history-events/issues
- npm.io page: https://npm.io/package/history-events

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.4 (latest) — 2015-08-10
- 1.0.3 — 2015-08-10
- 1.0.2 — 2015-08-07
- 1.0.1 — 2015-08-07
- 1.0.0 — 2015-08-07

## README

# [history](https://developer.mozilla.org/en-US/docs/Web/API/Window/history)-events

> Adds missing window.history events onpushstate, onreplacestate and onchangestate.

This module patches browser's `window.history` object and adds support for additional history events. You can use this module in a `polymorphic` applications (it only loads if inside a browser and does not raise an error on server side).

## Setup

```html
<script src="dist/history-events.min.js" type="text/javascript"></script>
```

If you are compiling assets using a bundler (e.g. [webpack](http://webpack.github.io/)) then you just do the `import` inside your main file.

```js
// es5
var history = require('history-events');
// es6
import history from 'history-events';
```

## Usage

```js
var history = require('history-events');

if (history.isHistorySupported()) {
  window.addEventListener('changestate', function(e) {
    console.log('URL changed');
  });

  window.history.pushState(null, null, '/login'); // `changestate` will be triggered
}
```

## API

### Window Events

* **onpopstate** is triggered when browser's back/forward button is pressed.
* **onpushstate** is triggered on `window.history.pushState` method call.
* **onreplacestate** is triggered on `window.history.replaceState` method call.
* **onchangestate** is triggered on `window.history.pushState` or `window.history.replaceState` method call or when browser's back/forward button is pressed.

### Module Methods

* **history.isHistorySupported()** returns true when `window.history` feature is supported by the environment.
* **addEventListener** registes a new event.
* **removeEventListener** unregistes a new event.
* **triggerEvent** triggers an event.

---
_Source: https://npm.io/package/history-events · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
