@shaper.org/vite-react-plugin 1.0.11 → 1.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/templates/main.ts +25 -2
package/package.json
CHANGED
package/templates/main.ts
CHANGED
|
@@ -108,7 +108,11 @@ export class ReactRouteMonitor {
|
|
|
108
108
|
this.iframeClient.onMessage((event) => {
|
|
109
109
|
const messageData = event.data;
|
|
110
110
|
if (messageData.type == "push-route") {
|
|
111
|
-
|
|
111
|
+
history.pushState(
|
|
112
|
+
{ type: "from-iframe-parent" },
|
|
113
|
+
"",
|
|
114
|
+
messageData.message.path,
|
|
115
|
+
);
|
|
112
116
|
}
|
|
113
117
|
});
|
|
114
118
|
}
|
|
@@ -129,8 +133,13 @@ export class ReactRouteMonitor {
|
|
|
129
133
|
|
|
130
134
|
patchHistory() {
|
|
131
135
|
history.pushState = (...args) => {
|
|
136
|
+
let shouldTrigger = true;
|
|
137
|
+
if (args[0] && args[0].type === "from-iframe-parent") {
|
|
138
|
+
args[0] = {};
|
|
139
|
+
shouldTrigger = false;
|
|
140
|
+
}
|
|
132
141
|
this.origPush.apply(history, args);
|
|
133
|
-
this.triggerRouteChange();
|
|
142
|
+
if (shouldTrigger) this.triggerRouteChange();
|
|
134
143
|
};
|
|
135
144
|
|
|
136
145
|
history.replaceState = (...args) => {
|
|
@@ -245,3 +254,17 @@ const monitor = new ReactRouteMonitor({
|
|
|
245
254
|
|
|
246
255
|
monitor.start();
|
|
247
256
|
monitor.triggerRoutes();
|
|
257
|
+
|
|
258
|
+
// // simulate parent message
|
|
259
|
+
// setTimeout(() => {
|
|
260
|
+
// console.log("Simulating parent message");
|
|
261
|
+
// window.dispatchEvent(
|
|
262
|
+
// new MessageEvent("message", {
|
|
263
|
+
// data: {
|
|
264
|
+
// type: "push-route",
|
|
265
|
+
// message: { path: "/test" },
|
|
266
|
+
// },
|
|
267
|
+
// origin: "http://localhost:5173",
|
|
268
|
+
// }),
|
|
269
|
+
// );
|
|
270
|
+
// }, 1000);
|