0.0.103 • Published 5 years ago
@arted/history v0.0.103
history
history is a JavaScript library that lets you easily manage session history anywhere JavaScript runs.
Installation
Using npm:
$ npm install --save history
Then with a module bundler like webpack, use as you would anything else:
// using ES6 modules
import createHistory from '@arted/history';
// using CommonJS modules
var createHistory = require('@arted/history');
Usage
Basic usage looks like this:
import createHistory from '@arted/history';
const history = createHistory();
// Get the current state.
const state = history.state;
// Listen for changes to the current location.
const unsubscribe = history.subscribe((state) => {
// state is an object as histories
console.log(state)
});
// Use push, replace, and go to navigate around.
history.go('/home', { method: 'REPLACE' });
// To stop listening, call the function returned from listen().
unsubscribe();
Navigation
history objects may be used programmatically change the current location using the following methods: