CJY0208 / react-router-cache-route

Route with cache for react-router V5 like <keep-alive /> in Vue
https://www.npmjs.com/package/react-router-cache-route
MIT License
1.14k stars 110 forks source link

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

Open yangjunpeng1993 opened 1 year ago

yangjunpeng1993 commented 1 year ago

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

xushijie10086 commented 1 year ago

同问

CJY0208 commented 1 year ago

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

withzhaoyu commented 1 year ago

同问 请问怎么解决的

xushijie10086 commented 1 year ago

这个库是真的很强大,文档也挺详细, 我已经完美实现了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}

))`