2017-01-29 17:36:21 +02:00
|
|
|
/**
|
|
|
|
* A helper wrapper service around window.history
|
|
|
|
*/
|
|
|
|
|
2017-05-25 22:11:57 +03:00
|
|
|
import createBrowserHistory from 'history/createBrowserHistory';
|
|
|
|
|
|
|
|
export const browserHistory = createBrowserHistory();
|
|
|
|
|
|
|
|
browserHistory.listen(() => {
|
|
|
|
patchHistory(browserHistory);
|
|
|
|
});
|
|
|
|
|
|
|
|
function patchHistory(history) {
|
|
|
|
Object.assign(history.location,
|
|
|
|
{query: new URLSearchParams(history.location.search)}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
patchHistory(browserHistory);
|
|
|
|
|
2017-01-29 17:36:21 +02:00
|
|
|
export default {
|
|
|
|
init() {
|
|
|
|
this.initialLength = window.history.length;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return {bool} - whether history.back() can be safetly called
|
|
|
|
*/
|
|
|
|
canGoBack() {
|
|
|
|
return document.referrer.includes(`${location.protocol}//${location.host}`)
|
|
|
|
|| this.initialLength < window.history.length;
|
|
|
|
}
|
2017-01-31 08:05:36 +02:00
|
|
|
};
|