Docs
导航菜单
导航菜单
用于网站导航的链接集合。
安装
npx shadcn-ui@latest add navigation-menu
用法
import {
NavigationMenu,
NavigationMenuContent,
NavigationMenuIndicator,
NavigationMenuItem,
NavigationMenuLink,
NavigationMenuList,
NavigationMenuTrigger,
NavigationMenuViewport,
} from "@/components/ui/navigation-menu"
<NavigationMenu>
<NavigationMenuList>
<NavigationMenuItem>
<NavigationMenuTrigger>项目一</NavigationMenuTrigger>
<NavigationMenuContent>
<NavigationMenuLink>链接</NavigationMenuLink>
</NavigationMenuContent>
</NavigationMenuItem>
</NavigationMenuList>
</NavigationMenu>
案例
Link 组件
使用 Next.js <Link />
组件时,可以使用 navigationMenuTriggerStyle()
为触发器应用正确的样式。
import { navigationMenuTriggerStyle } from "@/components/ui/navigation-menu"
<NavigationMenuItem>
<Link href="/docs" legacyBehavior passHref>
<NavigationMenuLink className={navigationMenuTriggerStyle()}>
文档
</NavigationMenuLink>
</Link>
</NavigationMenuItem>
有关处理客户端路由的更多信息,请参见 Radix UI 文档。