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

带有参数的页面,离开页面的时候useParams会返回undefined,导致无法维持原来的页面组件状态 #153

Closed yepyeel closed 1 year ago

CJY0208 commented 1 year ago

这个不是 cache-route 的问题,useParams 由 react-router 提供,如果需要实现上边的功能,可以自己缓存一下有效的 params,利用 cache-route 提供的生命周期功能对 params 进行手动更新

coolguy001tv commented 1 year ago

其实我觉得问题在于,useParams在正常情况下至少是返回的{}, 所以可以安全地使用类似于 const { companyCode } = useParams<IParams>(); 但现在因为useParams返回了undefined,导致我页面直接就报错白屏了……

see2ever commented 1 year ago

其实我觉得问题在于,useParams在正常情况下至少是返回的{}, 所以可以安全地使用类似于 const { companyCode } = useParams<IParams>(); 但现在因为useParams返回了undefined,导致我页面直接就报错白屏了……

useParams 也不是 cache-router 的问题啊