https://github.com/bendrucker/observ-history
Observable interface to the browser history API
https://github.com/bendrucker/observ-history
Last synced: about 1 year ago
JSON representation
Observable interface to the browser history API
- Host: GitHub
- URL: https://github.com/bendrucker/observ-history
- Owner: bendrucker
- License: mit
- Created: 2015-09-24T19:42:41.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2019-08-19T21:59:21.000Z (almost 7 years ago)
- Last Synced: 2024-11-20T06:49:00.709Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 8.79 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# observ-history [](https://travis-ci.org/bendrucker/observ-history) [](https://greenkeeper.io/)
> Observable interface to the browser history API
## Install
```
$ npm install --save observ-history
```
## Usage
```js
var history = require('observ-history')
history(function (path) {
//=> (popstate)
})
history()
//=> current path
history.set(path)
//=> pushState
```
## API
#### `history([listener])` -> `function`
Returns an unlisten function.
##### listener
Type: `function`
A function to call with the current path when the history changes and a [`popstate` event](https://developer.mozilla.org/en-US/docs/Web/Events/popstate) is fired. If no function is passed, the current path is returned.
#### `history.set(path)` -> `undefined`
Updates the history by calling [`pushState`](https://developer.mozilla.org/en-US/docs/Web/API/History/pushState).
## License
MIT © [Ben Drucker](http://bendrucker.me)