alitajs / umi-plugin-keep-alive

<KeepAlive> for umijs base on react-activation
https://www.npmjs.com/package/umi-plugin-keep-alive
MIT License
290 stars 23 forks source link

请教 umi一定要用这个插件么,如果不用是否有推荐方案 #80

Open MTTTM opened 2 years ago

MTTTM commented 2 years ago

请教 umi一定要用这个插件么,如果不用是否有推荐方案 或 项目使用了umi-plugin-keep-alive 那我有个npm包需要用到keepAlive,它是从umi导入还是从react-activation npm包安装了一下两个库 "umi": "^3.2.10", "umi-plugin-keep-alive": "^0.0.1-beta.34",

我发现两种都会导致缓存无效,从umi import的时候 npm包里面的代码ts会提示umi没有导出useAliveController 和KeepAlive元素,代码如下 import { KeepAlive, useAliveController } from 'umi';

改成 // @ts-ignore import { KeepAlive, useAliveController } from 'umi';

打包不报错,但是运行项目后,无法执行,报错如下 umi.deb8c82b.js:325505 Uncaught Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

react_devtools_backend.js:4026 The above error occurred in the component: in ProviderBridge (created by ProviderBridge) in ProviderBridge (created by ProviderBridge) in ProviderBridge (created by ProviderBridge) in ProviderBridge (created by ProviderBridge) in ProviderBridge (created by ProviderBridge) in ProviderBridge (created by ProviderBridge) in ProviderBridge (created by ProviderBridge) in ProviderBridge (created by Bridge) in Suspense (created by SuspenseBridge) in SuspenseBridge (created by Bridge) in ErrorBoundaryBridge (created by Bridge) in Bridge (created by Keeper) in div (created by Keeper) in div (created by Keeper)

CJY0208 commented 2 years ago

umi-plugin-keep-alive 是需要的,可以换从 react-activation 导出试试,另外需要看你是如何使用 KeepAlive 插件的,看报错可能是渲染了一个 undefined

FangHaydn commented 1 year ago

配置文件加上 plugins: ['umi-plugin-keep-alive'],