@alicloud/alfa-react 1.5.1-alpha.3 → 1.5.1-alpha.5
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/es/createApplication.js +13 -5
- package/es/version.js +1 -1
- package/lib/createApplication.js +13 -5
- package/lib/version.js +1 -1
- package/package.json +1 -1
- package/types/createAlfaApp.d.ts +4 -0
- package/types/createApplication.d.ts +2 -0
- package/types/version.d.ts +1 -1
package/es/createApplication.js
CHANGED
|
@@ -78,7 +78,8 @@ export default function createApplication(loader) {
|
|
|
78
78
|
dynamicConfig = props.dynamicConfig,
|
|
79
79
|
noCache = props.noCache,
|
|
80
80
|
syncHistory = props.syncHistory,
|
|
81
|
-
basename = props.basename
|
|
81
|
+
basename = props.basename,
|
|
82
|
+
onSyncHistory = props.onSyncHistory;
|
|
82
83
|
var handleExternalLink = customProps.handleExternalLink;
|
|
83
84
|
var _useState = useState(null),
|
|
84
85
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -97,9 +98,11 @@ export default function createApplication(loader) {
|
|
|
97
98
|
setReleaseVersion = _useState6[1];
|
|
98
99
|
$syncHistory.current = syncHistory;
|
|
99
100
|
$basename.current = basename;
|
|
100
|
-
|
|
101
|
+
|
|
102
|
+
// if (customProps.__innerStamp) console.warn('Please do not use __innerStamp which used in internal.');
|
|
101
103
|
// 更新标记,保证每次更新都会更新
|
|
102
104
|
customProps.__innerStamp = (+new Date()).toString(36);
|
|
105
|
+
customProps.__historyState = history.state;
|
|
103
106
|
if (customProps.path) customProps.path = addLeftSlash(customProps.path);
|
|
104
107
|
|
|
105
108
|
// 受控模式锁定一些参数
|
|
@@ -174,6 +177,12 @@ export default function createApplication(loader) {
|
|
|
174
177
|
popstateEvent.state = history.state;
|
|
175
178
|
(_App = App) === null || _App === void 0 ? void 0 : (_App$context$baseFram = _App.context.baseFrame) === null || _App$context$baseFram === void 0 ? void 0 : (_App$context$baseFram2 = _App$context$baseFram.contentWindow) === null || _App$context$baseFram2 === void 0 ? void 0 : _App$context$baseFram2.dispatchEvent(popstateEvent);
|
|
176
179
|
};
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* 因为要兼容历史逻辑,所以这段逻辑并不会执行
|
|
183
|
+
* react-router 的路由监听 callback 会先执行并更新子应用内部路由
|
|
184
|
+
* @returns
|
|
185
|
+
*/
|
|
177
186
|
var updateAppHistory = function updateAppHistory() {
|
|
178
187
|
if (App) {
|
|
179
188
|
var nextPath = peelPath(App.context.location);
|
|
@@ -192,7 +201,6 @@ export default function createApplication(loader) {
|
|
|
192
201
|
};
|
|
193
202
|
|
|
194
203
|
// 受控模式下,返回不会触发子应用内的路由更新,需要主动通知
|
|
195
|
-
// 这段逻辑不一定生效,因为我们已经劫持了沙箱内的 history.go 方法
|
|
196
204
|
if ($syncHistory.current) window.addEventListener('popstate', updateAppHistory);
|
|
197
205
|
_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
198
206
|
var _app$context$updateBo, _app$context, _app$context$baseFram;
|
|
@@ -255,6 +263,7 @@ export default function createApplication(loader) {
|
|
|
255
263
|
var nextPath = addBasename((_url === null || _url === void 0 ? void 0 : _url.toString()) || '', $basename.current);
|
|
256
264
|
if ("".concat(nextPath) !== peelPath(window.location)) {
|
|
257
265
|
window.history.pushState(data, unused, nextPath);
|
|
266
|
+
onSyncHistory && onSyncHistory('push', nextPath, data);
|
|
258
267
|
}
|
|
259
268
|
originalReplaceState(data, unused, _url);
|
|
260
269
|
} else {
|
|
@@ -265,6 +274,7 @@ export default function createApplication(loader) {
|
|
|
265
274
|
var nextPath = addBasename((_url === null || _url === void 0 ? void 0 : _url.toString()) || '', $basename.current);
|
|
266
275
|
if ($syncHistory.current) {
|
|
267
276
|
window.history.replaceState(data, unused, nextPath);
|
|
277
|
+
onSyncHistory && onSyncHistory('replace', nextPath, data);
|
|
268
278
|
}
|
|
269
279
|
originalReplaceState(data, unused, _url);
|
|
270
280
|
};
|
|
@@ -272,8 +282,6 @@ export default function createApplication(loader) {
|
|
|
272
282
|
// 劫持微应用的返回
|
|
273
283
|
frameWindow.history.go = function (n) {
|
|
274
284
|
window.history.go(n);
|
|
275
|
-
// 同步更新子应用的 state
|
|
276
|
-
originalReplaceState(history.state, '', peelPath(frameWindow.location));
|
|
277
285
|
};
|
|
278
286
|
}
|
|
279
287
|
}
|
package/es/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export var version = '1.5.1-alpha.
|
|
1
|
+
export var version = '1.5.1-alpha.5';
|
package/lib/createApplication.js
CHANGED
|
@@ -88,7 +88,8 @@ function createApplication(loader) {
|
|
|
88
88
|
dynamicConfig = props.dynamicConfig,
|
|
89
89
|
noCache = props.noCache,
|
|
90
90
|
syncHistory = props.syncHistory,
|
|
91
|
-
basename = props.basename
|
|
91
|
+
basename = props.basename,
|
|
92
|
+
onSyncHistory = props.onSyncHistory;
|
|
92
93
|
var handleExternalLink = customProps.handleExternalLink;
|
|
93
94
|
var _useState = (0, _react.useState)(null),
|
|
94
95
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
@@ -107,9 +108,11 @@ function createApplication(loader) {
|
|
|
107
108
|
setReleaseVersion = _useState6[1];
|
|
108
109
|
$syncHistory.current = syncHistory;
|
|
109
110
|
$basename.current = basename;
|
|
110
|
-
|
|
111
|
+
|
|
112
|
+
// if (customProps.__innerStamp) console.warn('Please do not use __innerStamp which used in internal.');
|
|
111
113
|
// 更新标记,保证每次更新都会更新
|
|
112
114
|
customProps.__innerStamp = (+new Date()).toString(36);
|
|
115
|
+
customProps.__historyState = history.state;
|
|
113
116
|
if (customProps.path) customProps.path = addLeftSlash(customProps.path);
|
|
114
117
|
|
|
115
118
|
// 受控模式锁定一些参数
|
|
@@ -184,6 +187,12 @@ function createApplication(loader) {
|
|
|
184
187
|
popstateEvent.state = history.state;
|
|
185
188
|
(_App = App) === null || _App === void 0 ? void 0 : (_App$context$baseFram = _App.context.baseFrame) === null || _App$context$baseFram === void 0 ? void 0 : (_App$context$baseFram2 = _App$context$baseFram.contentWindow) === null || _App$context$baseFram2 === void 0 ? void 0 : _App$context$baseFram2.dispatchEvent(popstateEvent);
|
|
186
189
|
};
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* 因为要兼容历史逻辑,所以这段逻辑并不会执行
|
|
193
|
+
* react-router 的路由监听 callback 会先执行并更新子应用内部路由
|
|
194
|
+
* @returns
|
|
195
|
+
*/
|
|
187
196
|
var updateAppHistory = function updateAppHistory() {
|
|
188
197
|
if (App) {
|
|
189
198
|
var nextPath = peelPath(App.context.location);
|
|
@@ -202,7 +211,6 @@ function createApplication(loader) {
|
|
|
202
211
|
};
|
|
203
212
|
|
|
204
213
|
// 受控模式下,返回不会触发子应用内的路由更新,需要主动通知
|
|
205
|
-
// 这段逻辑不一定生效,因为我们已经劫持了沙箱内的 history.go 方法
|
|
206
214
|
if ($syncHistory.current) window.addEventListener('popstate', updateAppHistory);
|
|
207
215
|
(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
208
216
|
var _app$context$updateBo, _app$context, _app$context$baseFram;
|
|
@@ -265,6 +273,7 @@ function createApplication(loader) {
|
|
|
265
273
|
var nextPath = addBasename((_url === null || _url === void 0 ? void 0 : _url.toString()) || '', $basename.current);
|
|
266
274
|
if ("".concat(nextPath) !== peelPath(window.location)) {
|
|
267
275
|
window.history.pushState(data, unused, nextPath);
|
|
276
|
+
onSyncHistory && onSyncHistory('push', nextPath, data);
|
|
268
277
|
}
|
|
269
278
|
originalReplaceState(data, unused, _url);
|
|
270
279
|
} else {
|
|
@@ -275,6 +284,7 @@ function createApplication(loader) {
|
|
|
275
284
|
var nextPath = addBasename((_url === null || _url === void 0 ? void 0 : _url.toString()) || '', $basename.current);
|
|
276
285
|
if ($syncHistory.current) {
|
|
277
286
|
window.history.replaceState(data, unused, nextPath);
|
|
287
|
+
onSyncHistory && onSyncHistory('replace', nextPath, data);
|
|
278
288
|
}
|
|
279
289
|
originalReplaceState(data, unused, _url);
|
|
280
290
|
};
|
|
@@ -282,8 +292,6 @@ function createApplication(loader) {
|
|
|
282
292
|
// 劫持微应用的返回
|
|
283
293
|
frameWindow.history.go = function (n) {
|
|
284
294
|
window.history.go(n);
|
|
285
|
-
// 同步更新子应用的 state
|
|
286
|
-
originalReplaceState(history.state, '', peelPath(frameWindow.location));
|
|
287
295
|
};
|
|
288
296
|
}
|
|
289
297
|
}
|
package/lib/version.js
CHANGED
package/package.json
CHANGED
package/types/createAlfaApp.d.ts
CHANGED
|
@@ -7,9 +7,11 @@ interface IProps<C = any> extends AlfaFactoryOption {
|
|
|
7
7
|
path?: string;
|
|
8
8
|
__injectHistory?: any;
|
|
9
9
|
__innerStamp?: string;
|
|
10
|
+
__historyState?: string;
|
|
10
11
|
handleExternalLink?: (href: string) => void;
|
|
11
12
|
};
|
|
12
13
|
syncHistory?: boolean;
|
|
14
|
+
onSyncHistory?: (type: 'replace' | 'push', path: string, data: any) => void;
|
|
13
15
|
basename?: string;
|
|
14
16
|
}
|
|
15
17
|
/**
|
package/types/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.5.1-alpha.
|
|
1
|
+
export declare const version = "1.5.1-alpha.5";
|