2017-01-29 21:06:21 +05:30
|
|
|
/**
|
|
|
|
* A helper wrapper service around window.history
|
|
|
|
*/
|
|
|
|
|
2019-06-30 19:02:50 +05:30
|
|
|
import { createBrowserHistory } from 'history';
|
2017-05-26 00:41:57 +05:30
|
|
|
|
|
|
|
export const browserHistory = createBrowserHistory();
|
|
|
|
|
|
|
|
browserHistory.listen(() => {
|
2019-11-27 14:33:32 +05:30
|
|
|
patchHistory(browserHistory);
|
2017-05-26 00:41:57 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
function patchHistory(history) {
|
2019-11-27 14:33:32 +05:30
|
|
|
Object.assign(history.location, {
|
|
|
|
query: new URLSearchParams(history.location.search),
|
|
|
|
});
|
2017-05-26 00:41:57 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
patchHistory(browserHistory);
|
|
|
|
|
2017-01-29 21:06:21 +05:30
|
|
|
export default {
|
2019-11-27 14:33:32 +05:30
|
|
|
init() {
|
|
|
|
this.initialLength = window.history.length;
|
|
|
|
},
|
2017-01-29 21:06:21 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
/**
|
2019-12-07 16:58:52 +05:30
|
|
|
* @returns {boolean} - whether history.back() can be safetly called
|
2019-11-27 14:33:32 +05:30
|
|
|
*/
|
|
|
|
canGoBack() {
|
|
|
|
return (
|
|
|
|
document.referrer.includes(`${location.protocol}//${location.host}`) ||
|
|
|
|
this.initialLength < window.history.length
|
|
|
|
);
|
|
|
|
},
|
2017-01-31 11:35:36 +05:30
|
|
|
};
|