@umijs/plugins 4.0.11 → 4.0.12
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,
|
|
@@ -100,13 +100,18 @@ export function patchMicroAppRoute(
|
|
|
100
100
|
const recursiveSearch = (
|
|
101
101
|
routes: IRouteProps[],
|
|
102
102
|
path: string,
|
|
103
|
-
|
|
103
|
+
parentPath: string,
|
|
104
|
+
): [IRouteProps, IRouteProps[], number, string] | null => {
|
|
104
105
|
for (let i = 0; i < routes.length; i++) {
|
|
105
106
|
if (routes[i].path === path) {
|
|
106
|
-
return routes[i];
|
|
107
|
+
return [routes[i], routes, i, parentPath];
|
|
107
108
|
}
|
|
108
109
|
if (routes[i].children && routes[i].children?.length) {
|
|
109
|
-
const found = recursiveSearch(
|
|
110
|
+
const found = recursiveSearch(
|
|
111
|
+
routes[i].children || [],
|
|
112
|
+
path,
|
|
113
|
+
routes[i].path,
|
|
114
|
+
);
|
|
110
115
|
if (found) {
|
|
111
116
|
return found;
|
|
112
117
|
}
|
|
@@ -116,23 +121,48 @@ const recursiveSearch = (
|
|
|
116
121
|
};
|
|
117
122
|
|
|
118
123
|
export function insertRoute(routes: IRouteProps[], microAppRoute: IRouteProps) {
|
|
119
|
-
const
|
|
124
|
+
const mod =
|
|
125
|
+
microAppRoute.appendChildTo || microAppRoute.insert
|
|
126
|
+
? 'appendChildTo'
|
|
127
|
+
: microAppRoute.insertBefore
|
|
128
|
+
? 'insertBefore'
|
|
129
|
+
: undefined;
|
|
130
|
+
const target =
|
|
131
|
+
microAppRoute.appendChildTo ||
|
|
132
|
+
microAppRoute.insert ||
|
|
133
|
+
microAppRoute.insertBefore;
|
|
134
|
+
const [found, foundParentRoutes = [], index = 0, parentPath] =
|
|
135
|
+
recursiveSearch(routes, target, '/') || [];
|
|
120
136
|
if (found) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
137
|
+
switch (mod) {
|
|
138
|
+
case 'appendChildTo':
|
|
139
|
+
if (
|
|
140
|
+
!microAppRoute.path ||
|
|
141
|
+
!found.path ||
|
|
142
|
+
!microAppRoute.path.startsWith(found.path)
|
|
143
|
+
) {
|
|
144
|
+
throw new Error(
|
|
145
|
+
`[plugin-qiankun]: path "${microAppRoute.path}" need to starts with "${found.path}"`,
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
found.exact = false;
|
|
149
|
+
found.children = found.children || [];
|
|
150
|
+
found.children.push(microAppRoute);
|
|
151
|
+
break;
|
|
152
|
+
case 'insertBefore':
|
|
153
|
+
if (
|
|
154
|
+
!microAppRoute.path ||
|
|
155
|
+
!found.path ||
|
|
156
|
+
!microAppRoute.path.startsWith(parentPath)
|
|
157
|
+
) {
|
|
158
|
+
throw new Error(
|
|
159
|
+
`[plugin-qiankun]: path "${microAppRoute.path}" need to starts with "${parentPath}"`,
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
foundParentRoutes.splice(index, 0, microAppRoute);
|
|
163
|
+
break;
|
|
129
164
|
}
|
|
130
|
-
found.exact = false;
|
|
131
|
-
found.children = found.children || [];
|
|
132
|
-
found.children.push(microAppRoute);
|
|
133
165
|
} else {
|
|
134
|
-
throw new Error(
|
|
135
|
-
`[plugin-qiankun]: path "${microAppRoute.insert}" not found`,
|
|
136
|
-
);
|
|
166
|
+
throw new Error(`[plugin-qiankun]: path "${target}" not found`);
|
|
137
167
|
}
|
|
138
168
|
}
|
|
@@ -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.12",
|
|
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.12",
|
|
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.12"
|
|
48
48
|
},
|
|
49
49
|
"publishConfig": {
|
|
50
50
|
"access": "public"
|