学员各页面缓存

This commit is contained in:
禺狨
2023-04-21 10:27:54 +08:00
parent 492270bfc3
commit 409fa080fc
6 changed files with 50 additions and 16 deletions

View File

@@ -0,0 +1,29 @@
import { useUpdate } from "ahooks";
import { useEffect, useRef } from "react";
import { useLocation, useOutlet } from "react-router-dom";
function KeepAlive() {
const componentList = useRef(new Map());
const outLet = useOutlet();
const { pathname } = useLocation();
const forceUpdate = useUpdate();
useEffect(() => {
if (!componentList.current.has(pathname)) {
componentList.current.set(pathname, outLet);
}
forceUpdate();
}, [pathname]);
return (
<div>
{Array.from(componentList.current).map(([key, component]) => (
<div key={key} style={{ display: pathname === key ? "block" : "none" }}>
{component}
</div>
))}
</div>
);
}
export default KeepAlive;

View File

@@ -50,7 +50,7 @@ const items = [
"user",
<i className="iconfont icon-icon-user" />,
[
getItem("学员", "/member", null, null, null),
getItem("学员", "/member/index", null, null, null),
getItem("部门", "/department", null, null, null),
],
null