@easyroute/core
Version:
Framework-agnostic router for JavaScript single-page applications
21 lines (19 loc) • 556 B
JavaScript
import { stripBase } from '../utils/stripBase';
export default function setHashMode() {
this.modeName = 'hash';
this.changeUrl = function (url) {
this.currentUrl = url;
window.location.hash = url;
};
this.go = function (howFar) {
window.history.go(howFar);
};
this.parseRoute(stripBase(window.location.hash, this.base) || '/');
window.addEventListener('hashchange', () => {
if (this.ignoreEvents) {
this.ignoreEvents = false;
return;
}
this.parseRoute(stripBase(window.location.hash, this.base));
});
}