Skip to content

Commit

Permalink
路径更新逻辑优化以防止刷新时丢失
Browse files Browse the repository at this point in the history
更新HomeLayout组件,使用`useLocation`获取当前路径以防止在刷新时丢失。该改进确保在浏览器刷新时,当前路径能正确更新,优化了用户导航的连贯性。
  • Loading branch information
www.zerocode.net.cn committed Sep 17, 2024
1 parent dd4d759 commit d5efadc
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/layouts/HomeLayout/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, {useEffect, useState} from 'react';
import {useLocation} from 'react-router-dom';
import defaultProps from './_defaultProps';
import {history, Link, Outlet} from "@@/exports";
import {PageContainer, ProCard, ProLayout, ProSettings, WaterMark} from '@ant-design/pro-components';
Expand Down Expand Up @@ -44,7 +45,8 @@ export const menuHeaderDropdown = (
);

const HomeLayout: React.FC<HomeLayoutLayoutProps> = props => {
const [pathname, setPathname] = useState('/project/home');
const location = useLocation();
const [pathname, setPathname] = useState(location.pathname);
const {setInitialState} = useModel('@@initialState');
const {tabDispatch} = useTabStore(state => ({tabDispatch: state.dispatch}));

Expand Down

0 comments on commit d5efadc

Please sign in to comment.