mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-08-16 15:30:59 +00:00
fix: bug when refresh page
This commit is contained in:
@@ -24,9 +24,7 @@ export default function HomeSidebar({
|
|||||||
handleRouteChange(pathname);
|
handleRouteChange(pathname);
|
||||||
}, [pathname]);
|
}, [pathname]);
|
||||||
|
|
||||||
const [selectedChild, setSelectedChild] = useState<SidebarChildVO>(
|
const [selectedChild, setSelectedChild] = useState<SidebarChildVO>();
|
||||||
sidebarConfigList[0],
|
|
||||||
);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log('HomeSidebar挂载完成');
|
console.log('HomeSidebar挂载完成');
|
||||||
@@ -42,7 +40,17 @@ export default function HomeSidebar({
|
|||||||
}
|
}
|
||||||
|
|
||||||
function initSelect() {
|
function initSelect() {
|
||||||
handleChildClick(sidebarConfigList[0]);
|
// 根据当前路径选择对应的菜单项
|
||||||
|
const currentPath = pathname;
|
||||||
|
const matchedChild = sidebarConfigList.find(
|
||||||
|
(childConfig) => childConfig.route === currentPath,
|
||||||
|
);
|
||||||
|
if (matchedChild) {
|
||||||
|
handleChildClick(matchedChild);
|
||||||
|
} else {
|
||||||
|
// 如果没有匹配的路径,则默认选择第一个
|
||||||
|
handleChildClick(sidebarConfigList[0]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleRoute(child: SidebarChildVO) {
|
function handleRoute(child: SidebarChildVO) {
|
||||||
@@ -98,7 +106,10 @@ export default function HomeSidebar({
|
|||||||
>
|
>
|
||||||
<SidebarChild
|
<SidebarChild
|
||||||
onClick={() => {}}
|
onClick={() => {}}
|
||||||
isSelected={selectedChild.id === config.id}
|
isSelected={
|
||||||
|
selectedChild !== undefined &&
|
||||||
|
selectedChild.id === config.id
|
||||||
|
}
|
||||||
icon={config.icon}
|
icon={config.icon}
|
||||||
name={config.name}
|
name={config.name}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user