diff --git a/src/pages/Container/Layout/index.jsx b/src/pages/Container/Layout/index.jsx
index 5c4b0a6..73e89ba 100644
--- a/src/pages/Container/Layout/index.jsx
+++ b/src/pages/Container/Layout/index.jsx
@@ -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) => {
diff --git a/src/pages/Container/index.js b/src/pages/Container/index.js
index 3c8a527..3c32105 100644
--- a/src/pages/Container/index.js
+++ b/src/pages/Container/index.js
@@ -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"
- ? {props.children}
+ ? {props.children}
: props.children;
return (