From 0af9171acdeb3012a60d32c81a26f24695dcf927 Mon Sep 17 00:00:00 2001 From: linxd <544554903@qq.com> Date: Thu, 17 Jul 2025 15:34:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9header=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E6=BF=80=E6=B4=BB=E8=8F=9C=E5=8D=95=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layouts/HeaderMenu.tsx | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/layouts/HeaderMenu.tsx b/src/layouts/HeaderMenu.tsx index 670c336..4e93e8e 100644 --- a/src/layouts/HeaderMenu.tsx +++ b/src/layouts/HeaderMenu.tsx @@ -1,7 +1,7 @@ import React, { useEffect, useState } from 'react'; import { Menu } from 'antd'; import Language from './Language'; -import { useIntl, Link, useHistory } from 'umi'; +import { useIntl, Link, useHistory, useLocation } from 'umi'; import User from './User'; interface IMenuItem { label: string; @@ -51,19 +51,17 @@ const HeaderMenu: React.FC = (props) => { //当前激活菜单 const [current, setCurrent] = useState('index'); const intl = useIntl(); - const history = useHistory(); + const location = useLocation(); useEffect(() => { - // 获取当前激活菜单 - const path = history.location.pathname; + const path = location.pathname; const menu = items.find((item) => item.path === path); if (menu) { setCurrent(menu.key); - }else{ - // 如果跳转的详情页面获取根级激活菜单 + } else { const rootActiveMenu = path.split('/')[1]; setCurrent(rootActiveMenu); } - }, [history.location.pathname]); + }, [location.pathname]); return (