レイアウトのリンク
すべてのレイアウトで共通のナビゲーション設定です。
概要
Fumadocs では、links prop を使ってレイアウトにナビゲーションリンクを追加できます。たとえば、「ショーケース」ページへのリンクを設置できます。


import type { BaseLayoutProps } from 'fumadocs-ui/layouts/shared';
export function baseOptions(): BaseLayoutProps {
return {
links: [],
};
}サポートされている項目の一覧は以下のとおりです。
リンク項目
URL/href へ移動するためのリンクです。外部リンクにすることもできます。
import { BookIcon } from 'lucide-react';
import type { BaseLayoutProps } from 'fumadocs-ui/layouts/shared';
export function baseOptions(): BaseLayoutProps {
return {
links: [
{
icon: <BookIcon />,
text: 'Blog',
url: '/blog',
// secondary のアイテムはナビゲーションバー上で異なる表示になります
secondary: false,
},
],
};
}アクティブモード
リンクをアクティブとしてマークする条件です。
| モード | 説明 |
|---|---|
url | 指定した URL を閲覧しているとき |
nested-url | 指定した URL とその子ページ (/blog/post など) を閲覧しているとき |
none | アクティブにしない |
import type { BaseLayoutProps } from 'fumadocs-ui/layouts/shared';
export function baseOptions(): BaseLayoutProps {
return {
links: [
{
text: 'Blog',
url: '/blog',
active: 'nested-url',
},
],
};
}アイコン項目
リンク項目と同じですが、アイコンボタンとして表示されます。 アイコン項目はデフォルトでセカンダリになります。
import { BookIcon } from 'lucide-react';
import type { BaseLayoutProps } from 'fumadocs-ui/layouts/shared';
export function baseOptions(): BaseLayoutProps {
return {
links: [
{
type: 'icon',
label: 'Visit Blog', // `aria-label`
icon: <BookIcon />,
text: 'Blog',
url: '/blog',
},
],
};
}カスタムアイテム
カスタムコンポーネントを表示します。
import type { BaseLayoutProps } from 'fumadocs-ui/layouts/shared';
export function baseOptions(): BaseLayoutProps {
return {
links: [
{
type: 'custom',
children: <Button variant="primary">Login</Button>,
secondary: true,
},
],
};
}GitHub URL
GitHub リポジトリへのリンク項目を追加するためのショートカットも用意されています。
import type { BaseLayoutProps } from 'fumadocs-ui/layouts/shared';
export function (): BaseLayoutProps {
return {
: 'https://github.com',
};
}通常のメニュー
複数のリンク項目を含むメニューです。
import type { BaseLayoutProps } from 'fumadocs-ui/layouts/shared';
export function baseOptions(): BaseLayoutProps {
return {
links: [
{
type: 'menu',
text: 'Guide',
items: [
{
text: 'Getting Started',
description: 'Learn to use Fumadocs',
url: '/docs',
},
],
},
],
};
}ナビゲーションメニュー
Home Layout では、ナビゲーションバーにナビゲーションメニュー (フルアニメーション対応) を追加できます。

import { baseOptions } from '@/lib/layout.shared';
import type { ReactNode } from 'react';
import { HomeLayout } from 'fumadocs-ui/layouts/home';
import {
NavbarMenu,
NavbarMenuContent,
NavbarMenuLink,
NavbarMenuTrigger,
} from 'fumadocs-ui/layouts/home/navbar';
export default function Layout({ children }: { children: ReactNode }) {
return (
<HomeLayout
{...baseOptions()}
links={[
{
type: 'custom',
// ナビゲーションバーにのみ表示(モバイルメニューには表示されません)
on: 'nav',
children: (
<NavbarMenu>
<NavbarMenuTrigger>Documentation</NavbarMenuTrigger>
<NavbarMenuContent>
<NavbarMenuLink href="/docs">Hello World</NavbarMenuLink>
</NavbarMenuContent>
</NavbarMenu>
),
},
// その他の項目
]}
>
{children}
</HomeLayout>
);
}How is this guide?
最終更新日
