@saber2pr/router
Version:
> react-router-dom by hooks api.
32 lines (31 loc) • 1.2 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
/*
* @Author: saber2pr
* @Date: 2019-06-04 14:30:23
* @Last Modified by: saber2pr
* @Last Modified time: 2019-06-06 13:51:17
*/
var HistoryStore_1 = require("./HistoryStore");
var execute_1 = require("./execute");
var schedular_1 = __importDefault(require("@saber2pr/schedular"));
function pushHash(url, scrollReset) {
if (!execute_1.getMaxLenChildStr(HistoryStore_1.HistoryStore.get(), url))
throw new Error();
HistoryStore_1.HistoryStore.current = url;
window.location.hash = "#" + url;
scrollReset && window.scroll(0, 0);
}
exports.pushHash = pushHash;
window.onhashchange = function () {
HistoryStore_1.HistoryStore.current = execute_1.execute(HistoryStore_1.HistoryStore.get(), location.hash.slice(1));
};
window.onload = function () {
new schedular_1.default().push({
expirationTime: 40,
idleCallback: function () { return execute_1.execute(HistoryStore_1.HistoryStore.get(), HistoryStore_1.HistoryStore.current); }
});
};