router fix

This commit is contained in:
Yuri Kuznetsov
2022-08-05 13:15:19 +03:00
parent e2a1e497fc
commit adefd7d3c5
+14 -36
View File
@@ -197,47 +197,25 @@ define('router', [], function () {
this.history = [];
let detectBackOrForward = (onBack, onForward) => {
let hashHistory = [window.location.hash];
let historyLength = window.history.length;
let hashHistory = [window.location.hash];
return function () {
let hash = window.location.hash, length = window.history.length;
window.addEventListener('hashchange', () => {
let hash = window.location.hash
if (hashHistory.length && historyLength === length) {
if (hashHistory[hashHistory.length - 2] === hash) {
hashHistory = hashHistory.slice(0, -1);
if (
hashHistory.length > 1 &&
hashHistory[hashHistory.length - 2] === hash
) {
hashHistory = hashHistory.slice(0, -1);
if (onBack) {
onBack();
}
return;
}
hashHistory.push(hash);
if (onForward) {
onForward();
}
return;
}
hashHistory.push(hash);
};
};
window.addEventListener(
'hashchange',
detectBackOrForward(() => {
this.backProcessed = true;
setTimeout(() => this.backProcessed = false, 50);
setTimeout(() => {
this.backProcessed = false;
}, 50);
})
);
return;
}
hashHistory.push(hash);
});
this.on('route', () => {
this.history.push(Backbone.history.fragment);