Fumadocs

Tanstack 启动

在 Tanstack Start 上设置 Fumadocs。

入门

🌐 Getting Started

在继续之前,请确保已配置:

🌐 Before continuing, make sure to configure:

  • Tailwind CSS 4
  • Fumadocs MDX:请按照 Vite 设置指南 并创建类似 lib/source.ts 的必要文件。

安装

🌐 Installation

npm i fumadocs-core fumadocs-ui

样式

🌐 Styles

将以下内容添加到你的 Tailwind CSS 文件中:

🌐 Add the following to your Tailwind CSS file:

styles/app.css
@import 'tailwindcss';
@import 'fumadocs-ui/css/neutral.css';
@import 'fumadocs-ui/css/preset.css';

创建页面

🌐 Create Pages

创建以下路线:

🌐 Create the following routes:

import type { BaseLayoutProps } from 'fumadocs-ui/layouts/shared';

export function baseOptions(): BaseLayoutProps {
  return {
    nav: {
      title: 'Tanstack Start',
    },
  };
}

将整个应用封装在 Fumadocs 提供者下:

🌐 Wrap your entire app under Fumadocs providers:

__root.tsx
import { createRootRoute, HeadContent, Outlet, Scripts } from '@tanstack/react-router';
import * as React from 'react';
import { RootProvider } from 'fumadocs-ui/provider/tanstack';

export const Route = createRootRoute({
  component: RootComponent,
});

function RootComponent() {
  return (
    <RootDocument>
      <Outlet />
    </RootDocument>
  );
}

function RootDocument({ children }: { children: React.ReactNode }) {
  return (
    <html suppressHydrationWarning>
      <head>
        <HeadContent />
      </head>
      <body className="flex flex-col min-h-screen">
        
        <RootProvider>{children}</RootProvider>
        <Scripts />
      </body>
    </html>
  );
}

完成

🌐 Done

你可以在 content/docs 开始撰写文档:

🌐 You can start writing documents at content/docs:

content/docs/index.mdx
---
title: Hello World
---

I love Fumadocs

Last updated on

On this page