dev_1.2
tangjie 2026-07-28 09:44:10 +08:00
parent 36f3896b60
commit 7955cc1595
2 changed files with 16 additions and 6 deletions

View File

@ -45,14 +45,22 @@ function saveState(tabs, activeKey) {
export default function SimulatedLayout({ children, history }) { export default function SimulatedLayout({ children, history }) {
const [collapsed, setCollapsed] = useState(false); const [collapsed, setCollapsed] = useState(false);
const [state, setState] = useState(loadState); 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(() => { useEffect(() => {
if (currentPath && !currentPath.endsWith("/container/")) { if (currentPath && !currentPath.endsWith("/container/")) {
addTab(currentPath); addTab(currentPath);
} }
}, []); // }, [currentPath]);
/* ---- 标签操作 ---- */ /* ---- 标签操作 ---- */
const addTab = useCallback((path) => { const addTab = useCallback((path) => {
@ -73,9 +81,11 @@ export default function SimulatedLayout({ children, history }) {
const navigateTo = useCallback((path) => { const navigateTo = useCallback((path) => {
if (path !== currentPath) { 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) => { const handleCloseTab = useCallback((targetKey) => {
setState((prev) => { setState((prev) => {

View File

@ -61,7 +61,7 @@ export default class Container extends React.Component {
function AppMiddle(props) { function AppMiddle(props) {
const content = process.env.NODE_ENV === "development" && !window.__POWERED_BY_QIANKUN__ && props.location.pathname !== "/container/Driver" 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; : props.children;
return ( return (