feat
parent
36f3896b60
commit
7955cc1595
|
|
@ -45,14 +45,22 @@ function saveState(tabs, activeKey) {
|
|||
export default function SimulatedLayout({ children, history }) {
|
||||
const [collapsed, setCollapsed] = useState(false);
|
||||
const [state, setState] = useState(loadState);
|
||||
const currentPath = window.location.pathname;
|
||||
const [currentPath, setCurrentPath] = useState(window.location.pathname);
|
||||
|
||||
// 页面加载时自动将当前路径加入标签
|
||||
// 监听路由变化,更新 currentPath
|
||||
useEffect(() => {
|
||||
const unlisten = history?.listen?.((location) => {
|
||||
setCurrentPath(location.pathname || window.location.pathname);
|
||||
});
|
||||
return () => unlisten?.();
|
||||
}, [history]);
|
||||
|
||||
// 路由变化时自动将当前路径加入标签
|
||||
useEffect(() => {
|
||||
if (currentPath && !currentPath.endsWith("/container/")) {
|
||||
addTab(currentPath);
|
||||
}
|
||||
}, []); // 仅挂载时执行一次
|
||||
}, [currentPath]);
|
||||
|
||||
/* ---- 标签操作 ---- */
|
||||
const addTab = useCallback((path) => {
|
||||
|
|
@ -73,9 +81,11 @@ export default function SimulatedLayout({ children, history }) {
|
|||
|
||||
const navigateTo = useCallback((path) => {
|
||||
if (path !== currentPath) {
|
||||
window.location.href = path;
|
||||
history.replace(path.replace(/^\/safetyEval/, ""));
|
||||
// history.listen 可能不存在,手动同步 currentPath
|
||||
setCurrentPath(window.location.pathname);
|
||||
}
|
||||
}, [currentPath]);
|
||||
}, [currentPath, history]);
|
||||
|
||||
const handleCloseTab = useCallback((targetKey) => {
|
||||
setState((prev) => {
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ export default class Container extends React.Component {
|
|||
function AppMiddle(props) {
|
||||
|
||||
const content = process.env.NODE_ENV === "development" && !window.__POWERED_BY_QIANKUN__ && props.location.pathname !== "/container/Driver"
|
||||
? <SimulatedLayout>{props.children}</SimulatedLayout>
|
||||
? <SimulatedLayout history={props.history}>{props.children}</SimulatedLayout>
|
||||
: props.children;
|
||||
|
||||
return (
|
||||
|
|
|
|||
Loading…
Reference in New Issue