Manual Installation
Add Fumadocs to an existing React Router project.
You can also let Fumadocs CLI set it up for you:
npx @fumadocs/cli initPrerequisites
Before continuing, make sure you have configured:
- Tailwind CSS 4.
- Fumadocs MDX: follow the Vite setup guide and create essential files like
lib/source.ts.
Good to Know
Fumadocs also supports other content sources, including Content Collections and headless CMS.
Getting Started
Install the packages:
npm i fumadocs-core fumadocs-ui@npm:@fumadocs/base-uiLike the templates, the command installs fumadocs-ui as an alias of @fumadocs/base-ui, the Base UI version of Fumadocs UI. For Radix UI, install fumadocs-ui without the alias.
Styles
Add the following to your Tailwind CSS file:
@import 'tailwindcss';
@import 'fumadocs-ui/css/neutral.css';
@import 'fumadocs-ui/css/preset.css';Root Provider
Wrap your entire app inside Root Provider, and add the required styles to body.
import { Links, Meta, Scripts, ScrollRestoration } from 'react-router';
import { RootProvider } from 'fumadocs-ui/provider/react-router';
import './app.css';
export function Layout({ children }: { children: React.ReactNode }) {
return (
<html lang="en" suppressHydrationWarning>
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<Meta />
<Links />
</head>
<body className="flex flex-col min-h-screen">
<RootProvider>{children}</RootProvider>
<ScrollRestoration />
<Scripts />
</body>
</html>
);
}Routes
Update your routes:
import { type RouteConfig, index, route } from '@react-router/dev/routes';
export default [
index('routes/home.tsx'),
route('docs/*', 'routes/docs.tsx'),
route('api/search', 'routes/search.ts'),
] satisfies RouteConfig;Create the following files:
import defaultMdxComponents from 'fumadocs-ui/mdx';
import type { MDXComponents } from 'mdx/types';
export function getMDXComponents(components?: MDXComponents) {
return {
...defaultMdxComponents,
...components,
} satisfies MDXComponents;
}
export const useMDXComponents = getMDXComponents;
declare global {
type MDXProvidedComponents = ReturnType<typeof getMDXComponents>;
}
In RSC mode, the docs route exports a ServerComponent instead of a loader and a page component:
import type { Route } from './+types/docs';
import { DocsLayout } from 'fumadocs-ui/layouts/docs';
import { DocsBody, DocsDescription, DocsPage, DocsTitle } from 'fumadocs-ui/layouts/docs/page';
import { source } from '@/lib/source';
import defaultMdxComponents from 'fumadocs-ui/mdx';
import { baseOptions } from '@/lib/layout.shared';
export function ServerComponent({ params }: Route.ComponentProps) {
const slugs = params['*'].split('/').filter((v) => v.length > 0);
const page = source.getPage(slugs);
if (!page) throw new Response('Not found', { status: 404 });
const { body: MDX } = page.data;
return (
<DocsLayout {...baseOptions()} tree={source.getPageTree()}>
<DocsPage toc={page.data.toc}>
<title>{page.data.title}</title>
<meta name="description" content={page.data.description} />
<DocsTitle>{page.data.title}</DocsTitle>
<DocsDescription>{page.data.description}</DocsDescription>
<DocsBody>
<MDX components={{ ...defaultMdxComponents }} />
</DocsBody>
</DocsPage>
</DocsLayout>
);
}
The search route uses ZBSearch. See Document Search to configure it.
Finish
Start the dev server and write your docs in content/docs:
---
title: Hello World
---
## Introduction
I love Fumadocs.How is this guide?
