### What problem does this PR solve? Fix:Modify the personal center style #10703 - All form-label font styles are no longer bold - Menus are not highlighted on first visit to the personal center ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
31 lines
863 B
TypeScript
31 lines
863 B
TypeScript
import { useLogout } from '@/hooks/login-hooks';
|
|
import { Routes } from '@/routes';
|
|
import { useCallback, useEffect, useState } from 'react';
|
|
import { useLocation, useNavigate } from 'umi';
|
|
|
|
export const useHandleMenuClick = () => {
|
|
const navigate = useNavigate();
|
|
const [active, setActive] = useState<Routes>();
|
|
const { logout } = useLogout();
|
|
const location = useLocation();
|
|
useEffect(() => {
|
|
const path = (location.pathname.split('/')?.[2] || '') as Routes;
|
|
if (path) {
|
|
setActive(('/' + path) as Routes);
|
|
}
|
|
}, [location]);
|
|
|
|
const handleMenuClick = useCallback(
|
|
(key: Routes) => () => {
|
|
if (key === Routes.Logout) {
|
|
logout();
|
|
} else {
|
|
setActive(key);
|
|
navigate(`${Routes.UserSetting}${key}`);
|
|
}
|
|
},
|
|
[logout, navigate],
|
|
);
|
|
|
|
return { handleMenuClick, active, setActive };
|
|
};
|