Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP]feat: keep alive #3084

Closed
wants to merge 10 commits into from
Closed

[WIP]feat: keep alive #3084

wants to merge 10 commits into from

Conversation

xiaohuoni
Copy link
Member

@xiaohuoni xiaohuoni commented Aug 29, 2019

Checklist
  • npm test passes
  • tests are included
  • documentation is changed or added
  • commit message follows commit guidelines
Description of change

只要route中配置属性keepAlive,就会被缓存

routes: [
    {
      path: '/',
      component: '../layouts/index',
      routes: [
        {
          path: '/',
          component: './index',
        },
        {
          path: '/list',
          component: './list',
          keepAlive: true,
        },
        {
          path: '/item',
          component: './item',
        },
      ],
    },
  ],

在不需要的时候,可以手动调用方法取消,下例的 /list 为上面设置了 keepAlive 的路由 path

import dropByCacheKey from 'umi/dropByCacheKey';
const clearCache = () => {
    dropByCacheKey('/list');
};

测试了添加了layout和不添加layout,都有效
2019-09-06 14 31 59


This change is Reviewable

@xiaohuoni
Copy link
Member Author

@CJY0208 看看

@CJY0208
Copy link
Member

CJY0208 commented Aug 29, 2019

很棒!能为 umi 间接做一点贡献,很荣幸

不过需要注意,目前的 CacheRoute 还无法与 react-transition-group 共同工作,启用 keepAlive 的路由将丢失路由动效

@LeoHuiyi
Copy link
Contributor

LeoHuiyi commented Aug 30, 2019

路由是按目录约定生成的要怎么支持keep alive?

@xiaohuoni
Copy link
Member Author

@LeoHuiyi 别着急,等云谦看看,方案可以的话,我会进一步支持。我们项目中用的都是约定式

@xiaohuoni xiaohuoni changed the title keep alive [WIP] keep alive Aug 30, 2019
@netlify
Copy link

netlify bot commented Sep 6, 2019

Ant Design Pro preview using the current branch umi

Built with commit 5175a22

https://deploy-preview-3084--pro-pre-umijs.netlify.com

@coveralls
Copy link

coveralls commented Sep 6, 2019

Pull Request Test Coverage Report for Build 6582

  • 6 of 8 (75.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.01%) to 41.582%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/umi/src/renderRoutes.js 6 8 75.0%
Totals Coverage Status
Change from base Build 6553: 0.01%
Covered Lines: 4378
Relevant Lines: 10464

💛 - Coveralls

@xiaohuoni xiaohuoni changed the title [WIP] keep alive [WIP] feat: keep alive Sep 12, 2019
@CodeMonkeyLin
Copy link

keep alive功能还没添加到umi版本么,我用最新的版本没有效果

@xiaohuoni xiaohuoni changed the title [WIP] feat: keep alive feat: keep alive Sep 19, 2019
@xiaohuoni
Copy link
Member Author

没合并呢

# Conflicts:
#	packages/umi-ui/client/yarn.lock
#	packages/umi/yarn.lock
@xiaohuoni xiaohuoni mentioned this pull request Oct 14, 2019
@xiaohuoni xiaohuoni changed the title feat: keep alive [WIP]feat: keep alive Oct 30, 2019
@xiaohuoni
Copy link
Member Author

嵌套路由相互跳转失效

# Conflicts:
#	packages/umi/test/dev.e2e.js
#	packages/umi/test/fixtures/build/ssr/test.js
@stale
Copy link

stale bot commented Jan 6, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jan 6, 2020
@xiaohuoni
Copy link
Member Author

跑不同,很多问题。
嵌套路由,还有hooks的结合,layout都要考虑。

@xiaohuoni xiaohuoni closed this Jan 9, 2020
@xiaohuoni xiaohuoni deleted the keep-alive branch January 9, 2020 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RFC] umi@3 支持Keep Alive 试用方案
5 participants