{navItems.map((item) => {
const Icon = item.icon;
- const active = isActive(item.href);
-
+
+ // 如果有子菜单,渲染下拉菜单
+ if (item.children) {
+ const hasActive = hasActiveChild(item.children);
+ const isOpen = openDropdown === item.name;
+
+ return (
+
+
+
+ {/* 下拉菜单 */}
+ {isOpen && (
+
+ {item.children.map((child) => {
+ const ChildIcon = child.icon;
+ const childActive = child.href ? isActive(child.href) : false;
+
+ return (
+
setOpenDropdown(null)}
+ >
+
+
+
{child.name}
+
{child.description}
+
+
+ );
+ })}
+
+ )}
+
+ );
+ }
+
+ // 普通导航项
+ const active = item.href ? isActive(item.href) : false;
+
return (