React Component keep-alive
English | 中文
Dependencies
React: 16.8.0+
Install
npm i keep-alive-comp
Usage
optional useStorage
param("sessionStorage"/"localStorage"): maintain cache after refresh("beforeRouteLeave" has been called)
if using
useStorage
, Components need to be used withSuspense
// example\index.tsximport configKeepAlive from 'keep-alive-comp'; // optional;
// example\Router.tsximport React Suspense from 'react';import HashRouter Route Switch from 'react-router-dom';import lazy from '@loadable/component';import KeepAlive from 'keep-alive-comp'; const List = ;const Detail = ; const Router: React.FC = children <HashRouter> children <Switch> <Route ="/" = /> <Route ="/detail/:id" = /> <Route ="*" = /> </Switch> </HashRouter>; ;
KeepAliveAssist
Component Example
component: list