'use client'; import { IconCirclePlusFilled, IconMail, type Icon } from '@tabler/icons-react'; import Link from 'next/link'; import { usePathname } from 'next/navigation'; import { Button } from '@nice/ui/components/button'; import { Badge } from '@nice/ui/components/badge'; import { SidebarGroup, SidebarGroupContent, SidebarGroupLabel, SidebarMenu, SidebarMenuButton, SidebarMenuItem, } from '@nice/ui/components/sidebar'; interface NavItem { title: string; url: string; icon?: Icon; badge?: string; } export function NavMain({ items, title, showQuickActions = false, }: { items: NavItem[]; title?: string; showQuickActions?: boolean; }) { const pathname = usePathname(); // 检查路径是否激活的函数 const isPathActive = (itemUrl: string) => { // 移除语言前缀进行比较 const cleanPathname = pathname.replace(/^\/[a-z]{2}(-[A-Z]{2})?/, '') || '/'; // 精确匹配 if (cleanPathname === itemUrl) { return true; } // 对于非根路径,检查是否以该路径开头 if (itemUrl !== '/' && cleanPathname.startsWith(itemUrl + '/')) { return true; } return false; }; return ( {title && {title}} {showQuickActions && ( 快速创建 )} {items.map((item) => { const isActive = isPathActive(item.url); return (
{item.icon && } {item.title}
{item.badge && ( {item.badge} )}
); })}
); }