mirror of
https://github.com/PlayEdu/backend
synced 2025-12-23 03:39:34 +08:00
学员各页面缓存
This commit is contained in:
29
src/compenents/keep-alive/index.tsx
Normal file
29
src/compenents/keep-alive/index.tsx
Normal 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;
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user