采用:react-activation
import KeepAlive from 'react-activation';
function Counter() {
const [count, setCount] = useState(0);
return (
count: {count}
);
}
const Welcome: React.FC = () => {
const intl = useIntl();
const [show, setShow] = useState(true);
return (
有KeepAlive
{show && (
)}
无KeepAlive
{show && }
);
};
export default Welcome;
入口app.tsx: childrenRender中使用
childrenRender: (children, props) => {
// if (initialState?.loading) return ;
return (
{children}
{!props.location?.pathname?.includes('/login') && (
{
setInitialState((preInitialState) => ({
...preInitialState,
settings,
}));
}}
/>
)}
);
},
我的调研:
React 页面间保存恢复状态的几种方法总结
umi使用umi-plugin-keep-alive实现页面缓存功能