Commit 90b3fab28ef53135f3cab1f69a4675f98a130857

Authored by vben
1 parent cdf2c59e

feat: routes with parameters can be cached

CHANGELOG.zh_CN.md
... ... @@ -6,6 +6,7 @@
6 6 - 增加富文本嵌入表单的示例
7 7 - 表单组件 schema 增加 `required`属性。简化配置
8 8 - openModal 和 openDrawer 第二个参数可以代替`transferModalData`传参到内部
  9 +- 带参路由可以被缓存
9 10  
10 11 ### ⚡ Performance Improvements
11 12  
... ...
src/layouts/default/LayoutContent.tsx
1 1 import { defineComponent } from 'vue';
2   -// import { Layout } from 'ant-design-vue';
  2 +import { Layout } from 'ant-design-vue';
  3 +import { RouterView } from 'vue-router';
  4 +
3 5 // hooks
4 6  
5 7 import { ContentEnum } from '/@/enums/appEnum';
6 8 import { appStore } from '/@/store/modules/app';
7   -import PageLayout from '/@/layouts/page/index';
  9 +// import PageLayout from '/@/layouts/page/index';
8 10 export default defineComponent({
9 11 name: 'DefaultLayoutContent',
10 12 setup() {
... ... @@ -13,9 +15,10 @@ export default defineComponent({
13 15 const { contentMode } = getProjectConfig;
14 16 const wrapClass = contentMode === ContentEnum.FULL ? 'full' : 'fixed';
15 17 return (
16   - // <Layout.Content class={`layout-content ${wrapClass} `}>
17   - <PageLayout class={`layout-content ${wrapClass} `} />
18   - // </Layout.Content>
  18 + <Layout.Content class={`layout-content ${wrapClass} `}>
  19 + {() => <RouterView />}
  20 + {/* <PageLayout class={`layout-content ${wrapClass} `} /> */}
  21 + </Layout.Content>
19 22 );
20 23 };
21 24 },
... ...
src/layouts/page/index.tsx
... ... @@ -44,10 +44,10 @@ export default defineComponent({
44 44 // TODO add key?
45 45 const Content = openCache ? (
46 46 <KeepAlive max={max} include={cacheTabs}>
47   - <Component />
  47 + <Component key={route.path} />
48 48 </KeepAlive>
49 49 ) : (
50   - <Component />
  50 + <Component key={route.path} />
51 51 );
52 52 return openRouterTransition ? (
53 53 <Transition
... ...
src/views/demo/feat/tab-params/index.vue
1 1 <template>
2 2 <div class="p-4">
3 3 Current Param : {{ params }}
4   - <!-- <input /> -->
  4 + <br />
  5 + Keep Alive
  6 + <input />
5 7 </div>
6 8 </template>
7 9 <script lang="ts">
... ...