@umijs/plugins 4.0.0-canary.20220506.1 → 4.0.0-canary.20220506.4
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 +2 -1
- package/dist/qiankun/master.js +1 -1
- package/dist/qiankun/slave.js +35 -29
- package/libs/qiankun/master/common.ts +6 -4
- package/libs/qiankun/master/getMicroAppRouteComponent.tsx.tpl +3 -5
- package/libs/qiankun/master/masterRuntimePlugin.tsx +5 -4
- package/package.json +3 -3
package/dist/layout.js
CHANGED
|
@@ -137,7 +137,8 @@ const { formatMessage } = useIntl();
|
|
|
137
137
|
}
|
|
138
138
|
if (menuItemProps.path && location.pathname !== menuItemProps.path) {
|
|
139
139
|
return (
|
|
140
|
-
|
|
140
|
+
// handle wildcard route path, for example /slave/* from qiankun
|
|
141
|
+
<Link to={menuItemProps.path.replace('/*', '')} target={menuItemProps.target}>
|
|
141
142
|
{defaultDom}
|
|
142
143
|
</Link>
|
|
143
144
|
);
|
package/dist/qiankun/master.js
CHANGED
|
@@ -48,7 +48,7 @@ exports.default = (api) => {
|
|
|
48
48
|
const normalizedRouteProps = JSON.stringify(routeProps).replace(/"/g, "'");
|
|
49
49
|
route.file = `(async () => {
|
|
50
50
|
const { getMicroAppRouteComponent } = await import('@@/plugin-qiankun-master/getMicroAppRouteComponent');
|
|
51
|
-
return getMicroAppRouteComponent({ appName: '${appName}', base: '${base}', masterHistoryType: '${masterHistoryType}', routeProps: ${normalizedRouteProps} })
|
|
51
|
+
return getMicroAppRouteComponent({ appName: '${appName}', base: '${base}', routePath: '${route.path}', masterHistoryType: '${masterHistoryType}', routeProps: ${normalizedRouteProps} })
|
|
52
52
|
})()`;
|
|
53
53
|
}
|
|
54
54
|
});
|
package/dist/qiankun/slave.js
CHANGED
|
@@ -30,7 +30,10 @@ exports.default = (api) => {
|
|
|
30
30
|
key: 'addExtraModels',
|
|
31
31
|
fn() {
|
|
32
32
|
return [
|
|
33
|
-
|
|
33
|
+
(0, withTmpPath_1.withTmpPath)({
|
|
34
|
+
api,
|
|
35
|
+
path: `qiankunModel.ts#{"namespace":"${constants_1.qiankunStateFromMasterModelNamespace}"}`,
|
|
36
|
+
}),
|
|
34
37
|
];
|
|
35
38
|
},
|
|
36
39
|
});
|
|
@@ -123,36 +126,39 @@ if (!window.__POWERED_BY_QIANKUN__) {
|
|
|
123
126
|
function getFileContent(file) {
|
|
124
127
|
return (0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../../libs/qiankun/slave', file), 'utf-8');
|
|
125
128
|
}
|
|
126
|
-
api.onGenerateFiles(
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
129
|
+
api.onGenerateFiles({
|
|
130
|
+
fn() {
|
|
131
|
+
// api.writeTmpFile({
|
|
132
|
+
// path: 'slaveOptions.ts',
|
|
133
|
+
// content: `
|
|
134
|
+
// let options = ${JSON.stringify((api.config.qiankun || {}).slave || {})};
|
|
135
|
+
// export const getSlaveOptions = () => options;
|
|
136
|
+
// export const setSlaveOptions = (newOpts) => options = ({ ...options, ...newOpts });
|
|
137
|
+
// `,
|
|
138
|
+
// });
|
|
139
|
+
[
|
|
140
|
+
'qiankunModel.ts',
|
|
141
|
+
'connectMaster.tsx',
|
|
142
|
+
'slaveRuntimePlugin.ts',
|
|
143
|
+
'lifecycles.ts',
|
|
144
|
+
].forEach((file) => {
|
|
145
|
+
api.writeTmpFile({
|
|
146
|
+
path: file.replace(/\.tpl$/, ''),
|
|
147
|
+
content: getFileContent(file)
|
|
148
|
+
.replace('__USE_MODEL__', api.isPluginEnable('model')
|
|
149
|
+
? `import { useModel } from '@@/plugin-model'`
|
|
150
|
+
: `const useModel = null;`)
|
|
151
|
+
.replace(/from 'qiankun'/g, `from '${(0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('qiankun/package')))}'`)
|
|
152
|
+
.replace(/from 'lodash\//g, `from '${(0, plugin_utils_1.winPath)((0, path_1.dirname)(require.resolve('lodash/package')))}/`),
|
|
153
|
+
});
|
|
149
154
|
});
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
content: `
|
|
155
|
+
api.writeTmpFile({
|
|
156
|
+
path: 'index.ts',
|
|
157
|
+
content: `
|
|
154
158
|
export { connectMaster } from './connectMaster';
|
|
155
159
|
`,
|
|
156
|
-
|
|
160
|
+
});
|
|
161
|
+
},
|
|
162
|
+
before: 'model',
|
|
157
163
|
});
|
|
158
164
|
};
|
|
@@ -48,6 +48,7 @@ export function patchMicroAppRoute(
|
|
|
48
48
|
getMicroAppRouteComponent: (opts: {
|
|
49
49
|
appName: string;
|
|
50
50
|
base: string;
|
|
51
|
+
routePath: string;
|
|
51
52
|
masterHistoryType: string;
|
|
52
53
|
routeProps?: any;
|
|
53
54
|
}) => string | ReactComponentElement<any>,
|
|
@@ -88,6 +89,7 @@ export function patchMicroAppRoute(
|
|
|
88
89
|
const opts = {
|
|
89
90
|
appName: microAppName,
|
|
90
91
|
base,
|
|
92
|
+
routePath: route.path,
|
|
91
93
|
masterHistoryType,
|
|
92
94
|
routeProps,
|
|
93
95
|
};
|
|
@@ -103,8 +105,8 @@ const recursiveSearch = (
|
|
|
103
105
|
if (routes[i].path === path) {
|
|
104
106
|
return routes[i];
|
|
105
107
|
}
|
|
106
|
-
if (routes[i].
|
|
107
|
-
const found = recursiveSearch(routes[i].
|
|
108
|
+
if (routes[i].children && routes[i].children?.length) {
|
|
109
|
+
const found = recursiveSearch(routes[i].children || [], path);
|
|
108
110
|
if (found) {
|
|
109
111
|
return found;
|
|
110
112
|
}
|
|
@@ -126,8 +128,8 @@ export function insertRoute(routes: IRouteProps[], microAppRoute: IRouteProps) {
|
|
|
126
128
|
);
|
|
127
129
|
}
|
|
128
130
|
found.exact = false;
|
|
129
|
-
found.
|
|
130
|
-
found.
|
|
131
|
+
found.children = found.children || [];
|
|
132
|
+
found.children.push(microAppRoute);
|
|
131
133
|
} else {
|
|
132
134
|
throw new Error(
|
|
133
135
|
`[plugin-qiankun]: path "${microAppRoute.insert}" not found`,
|
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { MicroApp } from './MicroApp';
|
|
3
|
-
import { useRouteData } from 'umi';
|
|
4
3
|
|
|
5
4
|
export function getMicroAppRouteComponent(opts: {
|
|
6
5
|
appName: string;
|
|
7
6
|
base: string;
|
|
7
|
+
routePath: string;
|
|
8
8
|
masterHistoryType: string;
|
|
9
9
|
routeProps?: any;
|
|
10
10
|
}) {
|
|
11
|
-
const { base, masterHistoryType, appName, routeProps } = opts;
|
|
11
|
+
const { base, masterHistoryType, appName, routeProps, routePath } = opts;
|
|
12
12
|
const RouteComponent = () => {
|
|
13
|
-
const { route } = useRouteData();
|
|
14
|
-
|
|
15
13
|
// 默认取静态配置的 base
|
|
16
14
|
let umiConfigBase = base === '/' ? '' : base;
|
|
17
15
|
|
|
18
16
|
// 拼接子应用挂载路由
|
|
19
|
-
let runtimeMatchedBase = umiConfigBase +
|
|
17
|
+
let runtimeMatchedBase = umiConfigBase + routePath.replace('/*', '');
|
|
20
18
|
|
|
21
19
|
{{#dynamicRoot}}
|
|
22
20
|
// @see https://github.com/umijs/umi/blob/master/packages/preset-built-in/src/plugins/commands/htmlUtils.ts#L102
|
|
@@ -34,10 +34,10 @@ function patchMicroAppRouteComponent(routes: any[]) {
|
|
|
34
34
|
const rootRoute = routes.find((route) => route.path === '/');
|
|
35
35
|
if (rootRoute) {
|
|
36
36
|
// 如果根路由是叶子节点,则直接返回其父节点
|
|
37
|
-
if (!rootRoute.
|
|
37
|
+
if (!rootRoute.children) {
|
|
38
38
|
return routes;
|
|
39
39
|
}
|
|
40
|
-
return getRootRoutes(rootRoute.
|
|
40
|
+
return getRootRoutes(rootRoute.children);
|
|
41
41
|
}
|
|
42
42
|
return routes;
|
|
43
43
|
};
|
|
@@ -50,11 +50,12 @@ function patchMicroAppRouteComponent(routes: any[]) {
|
|
|
50
50
|
const patchRoute = (route: any) => {
|
|
51
51
|
patchMicroAppRoute(route, getMicroAppRouteComponent, {
|
|
52
52
|
base,
|
|
53
|
+
routePath: route.path,
|
|
53
54
|
masterHistoryType,
|
|
54
55
|
routeBindingAlias,
|
|
55
56
|
});
|
|
56
|
-
if (route.
|
|
57
|
-
route.
|
|
57
|
+
if (route.children?.length) {
|
|
58
|
+
route.children.forEach(patchRoute);
|
|
58
59
|
}
|
|
59
60
|
};
|
|
60
61
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/plugins",
|
|
3
|
-
"version": "4.0.0-canary.20220506.
|
|
3
|
+
"version": "4.0.0-canary.20220506.4",
|
|
4
4
|
"description": "@umijs/plugins",
|
|
5
5
|
"homepage": "https://github.com/umijs/umi-next/tree/master/packages/plugins#readme",
|
|
6
6
|
"bugs": "https://github.com/umijs/umi-next/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": "^6.35.1",
|
|
28
|
-
"@umijs/bundler-utils": "4.0.0-canary.20220506.
|
|
28
|
+
"@umijs/bundler-utils": "4.0.0-canary.20220506.4",
|
|
29
29
|
"antd-dayjs-webpack-plugin": "^1.0.6",
|
|
30
30
|
"axios": "^0.26.1",
|
|
31
31
|
"babel-plugin-import": "^1.13.3",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"warning": "^4.0.3"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"umi": "4.0.0-canary.20220506.
|
|
47
|
+
"umi": "4.0.0-canary.20220506.4"
|
|
48
48
|
},
|
|
49
49
|
"publishConfig": {
|
|
50
50
|
"access": "public"
|