react-router-cache-route icon indicating copy to clipboard operation
react-router-cache-route copied to clipboard

带参数详情页面多份数据缓存如何做?

Open yangjunpeng1993 opened this issue 1 year ago • 4 comments

您好。 我们从列表页跳转至详情页,详情页需要通过网络请求数据,数据量比较大,所以在多个页签之间切换时会频繁请求网络数据。 我用了 multiple,但是如果不在 update 生命周期里面做更新,永远只能显示同样的缓存内容。我的疑问是如何判断当前页面应该走缓存还是走网络请求。

yangjunpeng1993 avatar Aug 03 '22 07:08 yangjunpeng1993

同问

xushijie10086 avatar Aug 12 '22 02:08 xushijie10086

意思是用了 multiple 还是不能缓存多份,需要手动通过 update 重新请求数据吗?能否提供复现用例

CJY0208 avatar Aug 15 '22 02:08 CJY0208

同问 请问怎么解决的

withzhaoyu avatar Feb 06 '23 08:02 withzhaoyu

这个库是真的很强大,文档也挺详细, 我已经完美实现了keep-alive的功能。

const renderCacheRoutes = () => routeList.map(({ component, path }, index) => ( <CacheRoute exact path={path} cacheKey={(props) => props.location?.pathname} when={'always'} key={path} multiple component={component} > </CacheRoute> ))

xushijie10086 avatar Feb 06 '23 08:02 xushijie10086