-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
嵌套路由,缓存了的组件每次都会重新调用 #118
Comments
目前每次 getComponent 都会重新生成一个组件定义,会被 React 认为是全新的组件,按首次渲染看待 不要在 map 里 getComponent,每个组件仅定义一次再试试 |
map只会跑一次,每个组件只会定义一次吧,没有用cacheswitch的话就只会渲染当前的组件 |
看了一下你代码,感觉确实像是只跑一次,现在是缓存完全不生效吗? 最好还是加一个 log 确认一下渲染情况 |
缓存生效了,就是缓存过的页面还会渲染一次,缓存越多那就越卡了,eg,访问页面路径A->B->C, 那访问C页面时,A,B缓存过的页面还是会rerender渲染一次 |
用 memo 包裹一下 getRoutes |
问题解决了吗 |
求教,嵌套路由,缓存了的组件每次都会重新调用,导致页面很慢
index.js (入口文件)
route.js
感谢关注
注: react-router-dom v5
The text was updated successfully, but these errors were encountered: