diff --git a/docs/reference/plugin/plugins/qiankun.md b/docs/reference/plugin/plugins/qiankun.md index 61706c49..06c98428 100644 --- a/docs/reference/plugin/plugins/qiankun.md +++ b/docs/reference/plugin/plugins/qiankun.md @@ -269,3 +269,24 @@ export default { - 主应用使用 props 的模式传递数据(参考主应用装载子应用配置一节) - 子应用在生命周期钩子中获取 props 消费数据(参考子应用运行时配置一节) + + +### MicroApp +| 属性 | 说明 | 类型 | 默认值 | +| ---- | ----------- | ------------- | ---------- | +| name | 子应用名称,传入`qiankun.main.apps`配置中的`name` | String | - | +| settings | 子应用配置信息 | Object | {} | +| props | 传入子应用的参数 | Object | {} | +| lifeCycles | 子应用生命周期钩子 | Object | {} | +| cacheName | 子应用缓存名称,配置后根据`name`+`cacheName`缓存子应用实例 | Object | - | + + +### MicroAppWithMemoHistory +| 属性 | 说明 | 类型 | 默认值 | +| ---- | ----------- | ------------- | ---------- | +| name | 子应用名称,传入`qiankun.main.apps`配置中的`name` | String | - | +| settings | 子应用配置信息 | Object | {} | +| props | 传入子应用的参数 | Object | {} | +| lifeCycles | 子应用生命周期钩子 | Object | {} | +| cacheName | 子应用缓存名称,配置后根据`name`+`cacheName`缓存子应用实例 | Object | - | +| url | 子应用的路由地址 | String | - | \ No newline at end of file diff --git a/packages/fes-plugin-qiankun/src/main/modifyRoutes.js b/packages/fes-plugin-qiankun/src/main/modifyRoutes.js index fbad283d..e785c3dd 100644 --- a/packages/fes-plugin-qiankun/src/main/modifyRoutes.js +++ b/packages/fes-plugin-qiankun/src/main/modifyRoutes.js @@ -2,11 +2,11 @@ import { defaultHistoryType } from '../constants'; function getMicroApp(options) { const { - key, microAppName, entry, masterHistoryType, base, namespace, ...normalizedRouteProps + key, microAppName, cacheName, masterHistoryType, base, namespace, ...normalizedRouteProps } = options; return `(() => { const { getMicroAppRouteComponent } = require('@@/${namespace}/getMicroAppRouteComponent'); -return getMicroAppRouteComponent({key: '${key}', appName: '${microAppName}', entry: '${entry}', base: '${base}', masterHistoryType: '${masterHistoryType}', routeProps: ${JSON.stringify(normalizedRouteProps)} }) +return getMicroAppRouteComponent({key: '${key}', appName: '${microAppName}', cacheName: '${cacheName}', base: '${base}', masterHistoryType: '${masterHistoryType}', routeProps: ${JSON.stringify(normalizedRouteProps)} }) })()`; } @@ -19,7 +19,7 @@ function modifyRoutesWithAttachMode({ if (route.meta && route.meta.microApp) { route.component = getMicroApp({ key: route.path, - entry: route.meta.entry ?? route.path, + cacheName: route.meta.cacheName ?? route.path, microAppName: route.meta.microApp, masterHistoryType, base, diff --git a/packages/fes-plugin-qiankun/src/main/runtime/MicroApp.tpl b/packages/fes-plugin-qiankun/src/main/runtime/MicroApp.tpl index 21ff3346..30809037 100644 --- a/packages/fes-plugin-qiankun/src/main/runtime/MicroApp.tpl +++ b/packages/fes-plugin-qiankun/src/main/runtime/MicroApp.tpl @@ -28,7 +28,7 @@ export const MicroApp = defineComponent({ type: String, required: true }, - entry: String, + cacheName: String, settings: Object, props: Object, lifeCycles: Object @@ -76,12 +76,12 @@ export const MicroApp = defineComponent({ // 只有当name变化时才重新加载新的子应用 const loadApp = () => { const appConfig = appConfigRef.value; - const { name, entry } = appConfig; + const { name, cacheName } = appConfig; // 加载新的 const app = loadMicroApp( { // 保证唯一 - name: `${name}_${props.entry || ''}`, + name: `${name}_${props.cacheName || ''}`, entry: entry, container: containerRef.value, props: {...propsConfigRef.value, ...attrs} diff --git a/packages/fes-plugin-qiankun/src/main/runtime/MicroAppWithMemoHistory.tpl b/packages/fes-plugin-qiankun/src/main/runtime/MicroAppWithMemoHistory.tpl index 58bfe3ac..e92bb7b7 100644 --- a/packages/fes-plugin-qiankun/src/main/runtime/MicroAppWithMemoHistory.tpl +++ b/packages/fes-plugin-qiankun/src/main/runtime/MicroAppWithMemoHistory.tpl @@ -14,7 +14,7 @@ export const MicroAppWithMemoHistory = defineComponent({ type: String, required: true }, - entry: String, + cacheName: String, settings: Object, props: Object, lifeCycles: Object, diff --git a/packages/fes-plugin-qiankun/src/main/runtime/getMicroAppRouteComponent.tpl b/packages/fes-plugin-qiankun/src/main/runtime/getMicroAppRouteComponent.tpl index 8a674320..c338fc60 100644 --- a/packages/fes-plugin-qiankun/src/main/runtime/getMicroAppRouteComponent.tpl +++ b/packages/fes-plugin-qiankun/src/main/runtime/getMicroAppRouteComponent.tpl @@ -3,11 +3,11 @@ import { MicroApp } from './MicroApp'; export function getMicroAppRouteComponent({ key, appName, - entry, + cacheName, base, masterHistoryType, routeProps }) { - return ; + return ; }