主要业务场景就是列表页跳转到详情页中,再回到列表页中,列表页还是保持之前的状态 比如:分页,搜索条件
const App = () => (
<Router>
<CacheSwitch>
<CacheRoute exact path="/list" component={List} />
<Route exact path="/item/:id" component={Item} />
<Route render={() => <div>404 Not Found</div>} />
</CacheSwitch>
</Router>
)
<CacheRoute path={item.path} key={item.path} cacheKey={"MyComponent"} exact when={whenFunction(item.applyRouteName)} render={route => ( <BaseView key={idx} {...route} handleHeader={handleHeader} handleSlider={handleSlider} listenRouterPath={listenRouterPath} > <Components {...route} /> </BaseView> )} />
react页面缓存插件 react-router-cache-router
原文:https://www.cnblogs.com/shine1234/p/15222336.html