1 |
|
2 |
|
3 | document.domain = window.location.hostname;
|
4 |
|
5 | const codelift = (action, ...args) => {
|
6 | window.top.postMessage(
|
7 | {
|
8 | source: "codelift",
|
9 | payload: { action, args }
|
10 | },
|
11 | "*"
|
12 | );
|
13 | };
|
14 |
|
15 | codelift("setPath", window.location.href.split(window.location.origin).pop());
|
16 |
|
17 |
|
18 | ["pushState", "replaceState"].forEach(method => {
|
19 | const original = window.history[method];
|
20 |
|
21 | window.history[method] = (...args) => {
|
22 | original.apply(window.history, args);
|
23 | codelift("syncPath");
|
24 | };
|
25 | });
|
26 |
|
27 | window.addEventListener("popstate", () => codelift("syncPath"));
|
28 |
|
29 |
|
30 | if (module.hot) {
|
31 |
|
32 | module.hot.addStatusHandler(status => {
|
33 | codelift("handleStatus", status);
|
34 | });
|
35 | }
|
36 |
|
37 | module.exports = function register({ React, ReactDOM }) {
|
38 | if (!window.React) {
|
39 | window.React = React;
|
40 | }
|
41 |
|
42 | if (!window.ReactDOM) {
|
43 | window.ReactDOM = ReactDOM;
|
44 | }
|
45 | };
|