@umijs/plugins 4.0.10 → 4.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/dist/layout.js
CHANGED
|
@@ -253,7 +253,7 @@ const { formatMessage } = useIntl();
|
|
|
253
253
|
type InitDataType = ReturnType<typeof InitialStateType>;
|
|
254
254
|
` : "type InitDataType = any;"}
|
|
255
255
|
|
|
256
|
-
import { IConfigFromPlugins } from '@@/core/pluginConfig';
|
|
256
|
+
import type { IConfigFromPlugins } from '@@/core/pluginConfig';
|
|
257
257
|
|
|
258
258
|
export type RunTimeLayoutConfig = (initData: InitDataType) => Omit<
|
|
259
259
|
ProLayoutProps,
|
package/dist/request.js
CHANGED
|
@@ -18,13 +18,12 @@ import React, {
|
|
|
18
18
|
useRef,
|
|
19
19
|
useState,
|
|
20
20
|
} from 'react';
|
|
21
|
+
import { qiankunStateForSlaveModelNamespace } from './constants';
|
|
21
22
|
import { ErrorBoundary } from './ErrorBoundary';
|
|
22
23
|
import { getMasterOptions } from './masterOptions';
|
|
23
24
|
import MicroAppLoader from './MicroAppLoader';
|
|
24
25
|
import { MasterOptions } from './types';
|
|
25
26
|
|
|
26
|
-
const qiankunStateForSlaveModelNamespace = '@@qiankunStateForSlave';
|
|
27
|
-
|
|
28
27
|
type HashHistory = {
|
|
29
28
|
type?: 'hash';
|
|
30
29
|
} & any;
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import React, { ReactComponentElement } from 'react';
|
|
9
|
-
import type
|
|
9
|
+
import { Navigate, type IRouteProps } from 'umi';
|
|
10
10
|
|
|
11
11
|
export const defaultMountContainerId = 'root-subapp';
|
|
12
12
|
|
|
@@ -94,19 +94,30 @@ export function patchMicroAppRoute(
|
|
|
94
94
|
routeProps,
|
|
95
95
|
};
|
|
96
96
|
route.element = React.createElement(getMicroAppRouteComponent(opts), null);
|
|
97
|
+
} else if (route.redirect) {
|
|
98
|
+
// patchClientRoutes 插入的 redirect 不会被转换,所以这里需要手动处理成重定向组件
|
|
99
|
+
route.element = React.createElement(Navigate, {
|
|
100
|
+
to: route.redirect,
|
|
101
|
+
replace: true,
|
|
102
|
+
});
|
|
97
103
|
}
|
|
98
104
|
}
|
|
99
105
|
|
|
100
106
|
const recursiveSearch = (
|
|
101
107
|
routes: IRouteProps[],
|
|
102
108
|
path: string,
|
|
103
|
-
|
|
109
|
+
parentPath: string,
|
|
110
|
+
): [IRouteProps, IRouteProps[], number, string] | null => {
|
|
104
111
|
for (let i = 0; i < routes.length; i++) {
|
|
105
112
|
if (routes[i].path === path) {
|
|
106
|
-
return routes[i];
|
|
113
|
+
return [routes[i], routes, i, parentPath];
|
|
107
114
|
}
|
|
108
115
|
if (routes[i].children && routes[i].children?.length) {
|
|
109
|
-
const found = recursiveSearch(
|
|
116
|
+
const found = recursiveSearch(
|
|
117
|
+
routes[i].children || [],
|
|
118
|
+
path,
|
|
119
|
+
routes[i].path,
|
|
120
|
+
);
|
|
110
121
|
if (found) {
|
|
111
122
|
return found;
|
|
112
123
|
}
|
|
@@ -116,23 +127,48 @@ const recursiveSearch = (
|
|
|
116
127
|
};
|
|
117
128
|
|
|
118
129
|
export function insertRoute(routes: IRouteProps[], microAppRoute: IRouteProps) {
|
|
119
|
-
const
|
|
130
|
+
const mod =
|
|
131
|
+
microAppRoute.appendChildTo || microAppRoute.insert
|
|
132
|
+
? 'appendChildTo'
|
|
133
|
+
: microAppRoute.insertBefore
|
|
134
|
+
? 'insertBefore'
|
|
135
|
+
: undefined;
|
|
136
|
+
const target =
|
|
137
|
+
microAppRoute.appendChildTo ||
|
|
138
|
+
microAppRoute.insert ||
|
|
139
|
+
microAppRoute.insertBefore;
|
|
140
|
+
const [found, foundParentRoutes = [], index = 0, parentPath] =
|
|
141
|
+
recursiveSearch(routes, target, '/') || [];
|
|
120
142
|
if (found) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
143
|
+
switch (mod) {
|
|
144
|
+
case 'appendChildTo':
|
|
145
|
+
if (
|
|
146
|
+
!microAppRoute.path ||
|
|
147
|
+
!found.path ||
|
|
148
|
+
!microAppRoute.path.startsWith(found.path)
|
|
149
|
+
) {
|
|
150
|
+
throw new Error(
|
|
151
|
+
`[plugin-qiankun]: path "${microAppRoute.path}" need to starts with "${found.path}"`,
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
found.exact = false;
|
|
155
|
+
found.children = found.children || [];
|
|
156
|
+
found.children.push(microAppRoute);
|
|
157
|
+
break;
|
|
158
|
+
case 'insertBefore':
|
|
159
|
+
if (
|
|
160
|
+
!microAppRoute.path ||
|
|
161
|
+
!found.path ||
|
|
162
|
+
!microAppRoute.path.startsWith(parentPath)
|
|
163
|
+
) {
|
|
164
|
+
throw new Error(
|
|
165
|
+
`[plugin-qiankun]: path "${microAppRoute.path}" need to starts with "${parentPath}"`,
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
foundParentRoutes.splice(index, 0, microAppRoute);
|
|
169
|
+
break;
|
|
129
170
|
}
|
|
130
|
-
found.exact = false;
|
|
131
|
-
found.children = found.children || [];
|
|
132
|
-
found.children.push(microAppRoute);
|
|
133
171
|
} else {
|
|
134
|
-
throw new Error(
|
|
135
|
-
`[plugin-qiankun]: path "${microAppRoute.insert}" not found`,
|
|
136
|
-
);
|
|
172
|
+
throw new Error(`[plugin-qiankun]: path "${target}" not found`);
|
|
137
173
|
}
|
|
138
174
|
}
|
|
@@ -24,7 +24,9 @@ async function getMasterRuntime() {
|
|
|
24
24
|
|
|
25
25
|
// modify route with "microApp" attribute to use real component
|
|
26
26
|
function patchMicroAppRouteComponent(routes: any[]) {
|
|
27
|
-
const insertRoutes = microAppRuntimeRoutes.filter(
|
|
27
|
+
const insertRoutes = microAppRuntimeRoutes.filter(
|
|
28
|
+
(r) => r.insert || r.insertBefore || r.appendChildTo,
|
|
29
|
+
);
|
|
28
30
|
// 先处理 insert 配置
|
|
29
31
|
insertRoutes.forEach((route) => {
|
|
30
32
|
insertRoute(routes, route);
|
|
@@ -60,7 +62,13 @@ function patchMicroAppRouteComponent(routes: any[]) {
|
|
|
60
62
|
};
|
|
61
63
|
|
|
62
64
|
patchRoute(microAppRoute);
|
|
63
|
-
|
|
65
|
+
if (
|
|
66
|
+
!microAppRoute.insert &&
|
|
67
|
+
!microAppRoute.insertBefore &&
|
|
68
|
+
!microAppRoute.appendChildTo
|
|
69
|
+
) {
|
|
70
|
+
rootRoutes.unshift(microAppRoute);
|
|
71
|
+
}
|
|
64
72
|
});
|
|
65
73
|
}
|
|
66
74
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/plugins",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.13",
|
|
4
4
|
"description": "@umijs/plugins",
|
|
5
5
|
"homepage": "https://github.com/umijs/umi/tree/master/packages/plugins#readme",
|
|
6
6
|
"bugs": "https://github.com/umijs/umi/issues",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"@ahooksjs/use-request": "^2.0.0",
|
|
26
26
|
"@ant-design/icons": "^4.7.0",
|
|
27
27
|
"@ant-design/pro-layout": "^7.0.1-beta.28",
|
|
28
|
-
"@umijs/bundler-utils": "4.0.
|
|
28
|
+
"@umijs/bundler-utils": "4.0.13",
|
|
29
29
|
"antd-dayjs-webpack-plugin": "^1.0.6",
|
|
30
30
|
"axios": "^0.27.2",
|
|
31
31
|
"babel-plugin-import": "^1.13.5",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"warning": "^4.0.3"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"umi": "4.0.
|
|
47
|
+
"umi": "4.0.13"
|
|
48
48
|
},
|
|
49
49
|
"publishConfig": {
|
|
50
50
|
"access": "public"
|