irychen / keepalive-for-react

React KeepAlive is a component that can cache the state of the component and reuse it when needed.
MIT License
162 stars 32 forks source link

Does it support nextjs route cache? #4

Closed leo-lucky-hub closed 5 months ago

leo-lucky-hub commented 5 months ago

实际并没有缓存

irychen commented 5 months ago

Currently, next.js routing is not supported.

leo-lucky-hub commented 5 months ago

有什么好的方案吗,因为我看目前,很多第三方都过时了

irychen commented 5 months ago

退而求其次,你可以把缓存做在页面内,而不是routing上。

leo-lucky-hub commented 5 months ago

但是我路由也想变化,如何保证路由变化,而已经打开的画面,重新切回去,画面内容不变呢

irychen commented 5 months ago

可以考虑将页面数据缓存到localstorage里面

leo-lucky-hub commented 5 months ago

关键打开的画面可能会很多,还有iframe的画面,感觉不太行,放到localstorage,使用Portal createPortal可能实现吗

irychen commented 5 months ago

确实是一个比较棘手的问题,目前这个项目还没考虑到实现支持ssr路由方案。

leo-lucky-hub commented 5 months ago

其实我们在代码里面都写了'use client'; 把组件变为了客户端组件了

irychen commented 5 months ago

但是nextjs的路由是不支持的

leo-lucky-hub commented 5 months ago

但是nextjs的路由是不支持的

这个是什么意思?是当前库不支持?还是nextjs的app router 的问题?

irychen commented 5 months ago

当前库不支持nextjs的路由级别keepalive,只支持react-router-dom v6

leo-lucky-hub commented 5 months ago

因为现在想做的就是menu菜单,点击一个菜单,显示一个tab,每个打开的tab切换,页面内容不重新加载,使用 之前打开过的,这个有什么方式吗?因为现在是app router,每次进入到layout的children都会变化,所以内容就变化了

leo-lucky-hub commented 5 months ago

或者说,用你现在的原理,实现一下nextjs的app router?

irychen commented 5 months ago

或许你可以尝试一下Nextjs Dynamic Routes

irychen commented 5 months ago

测试了下可以实现

leo-lucky-hub commented 5 months ago

如何实现,有代码吗?是nextjs app router吗?

irychen commented 5 months ago

image 技术交流群