1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| import { history as RouterHistory } from "award-router"; import { createLocation } from "history";
function hasBasename(path, prefix) { return ( path.toLowerCase().indexOf(prefix.toLowerCase()) === 0 && "/?#".indexOf(path.charAt(prefix.length)) !== -1 ); }
function stripBasename(path, prefix) { return hasBasename(path, prefix) ? path.substr(prefix.length) : path; }
let parentHistory = window.parent.history; let localReplaceState = history.replaceState; history.pushState = function () { if (arguments[0] && arguments[0].state === "null") { return; } parentHistory.pushState.apply(parentHistory, arguments); localReplaceState.apply(history, arguments); }; history.replaceState = function () { parentHistory.replaceState.apply(parentHistory, arguments); localReplaceState.apply(history, arguments); }; window.parent.addEventListener("popstate", function (e) { let _ref = e.state || {}; let key = _ref.key; let state = _ref.state;
let _window$location = window.parent.location; let pathname = _window$location.pathname; let search = _window$location.search; let hash = _window$location.hash; let path = pathname + search + hash; path = stripBasename(path, "/gatekeeper/lego"); const location = createLocation(path, state, key); localReplaceState.apply(history, [ "", "", location.pathname + location.search, ]); RouterHistory.push({ pathname: location.pathname, search: location.search, state: "null", }); });
|