mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-11-10 01:52:04 +05:30
36 lines
732 B
JavaScript
36 lines
732 B
JavaScript
/**
|
|
* A helper wrapper service around window.history
|
|
*/
|
|
|
|
import { createBrowserHistory } from 'history';
|
|
|
|
export const browserHistory = createBrowserHistory();
|
|
|
|
browserHistory.listen(() => {
|
|
patchHistory(browserHistory);
|
|
});
|
|
|
|
function patchHistory(history) {
|
|
Object.assign(history.location, {
|
|
query: new URLSearchParams(history.location.search),
|
|
});
|
|
}
|
|
|
|
patchHistory(browserHistory);
|
|
|
|
export default {
|
|
init() {
|
|
this.initialLength = window.history.length;
|
|
},
|
|
|
|
/**
|
|
* @returns {boolean} - whether history.back() can be safetly called
|
|
*/
|
|
canGoBack() {
|
|
return (
|
|
document.referrer.includes(`${location.protocol}//${location.host}`) ||
|
|
this.initialLength < window.history.length
|
|
);
|
|
},
|
|
};
|