Consistent API of HTML5 history API and hash fragments control.
npm install common-history
common-history consist of HashLocation
and HistoryLocation
.
It provides same interface.
-
HashLocation
is wrap hash fragments control. -
HistoryLocation
is wrap HTML5 history API.
// ececute http://example.com/
import {HashLocation} from 'common-history';
const hashLocation = new HashLocation();
// It is executed each time the location is changed.
hashLocation.addListener(changes => {
let {path, type} = changes;
console.log('current path:' + path);
console.log('transition type:' + type);
console.log(location.href);
});
hashLocation.push('/path/to');
// current path: /path/to
// transition type: PUSH
// http://example.com/#/path/to
(string): The path of current location. In hashLocation deal with hash fragments.
Adds a function to be called by a location changes.
- listener (function): The listener of location changes.
Listener is executed when the following:
- In HashLocation when
hashchange
event was dispatched. - In HistoryLocation when
popstate
event was dispatched. - In HistoryLocation when execute of
push
andreplace
.
Stop calling the given function.
- listener (function): The listener of location changes.
Change the URL in the browser’s location bar without page transition.
- path (string): The path of destination.
Change the URL in the browser’s location bar without page transition. It does not remain in the history.
- path (string): The path of destination.
Go back one entry in the history.
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request
MIT License