Use Pages
Docusaurus support MD/MDX/JS/JSX/TSX
format for pages.
Files under src/pages
will be treated as site pages.
Creating Pagesβ
MD Exampleβ
Create a file named demo-page.md
under src/pages/
.
Click to see MD example code
---
# Frontmatter, can be empty.
# Will use site title if empty.
title: Page Title
---
# Markdown Page
This is a Markdown page
MDX Exampleβ
Docusaurus has built-in support for MDX v1, which allows you to write JSX within your Markdown files and render them as React components.
Create a file named demo-page.mdx
under src/pages/
.
Click to see MDX example code
---
title: Page Title
---
export const Highlight = ({children, color}) => (
<span
style={{
backgroundColor: color,
borderRadius: '2px',
color: '#fff',
padding: '0.2rem',
}}>
{children}
</span>
);
# MDX Page
<Highlight color="#25c2a0">Docusaurus green</Highlight> and <Highlight color="#1877F2">Facebook blue</Highlight> are my favorite colors.
TSX Exampleβ
Create a file named demo-page.tsx
under src/pages/
. Docusaurus is based on react, so you can build pages as a react page.
Click to see TSX example code
import React from "react";
import clsx from "clsx";
import Layout from "@theme/Layout";
import Link from "@docusaurus/Link";
import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
import HomepageFeatures from "../components/HomepageFeatures";
function HomepageHeader() {
const { siteConfig } = useDocusaurusContext();
return (
<header className={clsx("hero hero--primary")}>
<div className="container">
<h1 className="hero__title">{siteConfig.title}</h1>
<p className="hero__subtitle">{siteConfig.tagline}</p>
<div>
<Link className="button" to="/docs/start">
Get started
</Link>
</div>
</div>
</header>
);
}
export default function Page(): JSX.Element {
const { siteConfig } = useDocusaurusContext();
return (
<Layout
title={`Hello from ${siteConfig.title}`}
description="Description will go into a meta tag in <head />"
>
<HomepageHeader />
<main>This is a Homepage using TSX</main>
</Layout>
);
}
Use Page for Homepageβ
Since most project has it's own website, and people sometimes just need to quick start a docs site, this template is pre-configurated for docs focused site. The docs
is at the root for this website.
1. Create a homepage fileβ
File named index
under src/pages
will be treated as site homepage by default.
This can be in MD/MDX/JS/JSX/TSX
format.
Click to see MD example code
---
title: Home
---
# Markdown Page
This is a Markdown page
2. Update default docs fileβ
Currently this template use docs/start.md
as homepage.
Remove slug: /
in the frontmatter and save the file:
---
sidebar_position: 1
- slug: /
---
3. Change docs route pathβ
Change the line of routeBasePath: '/'
under docs presets:
const config = {
presets: [
[
'classic',
({
docs: {
- routeBasePath: '/',
+ routeBasePath: '/docs',
},
}),
],
],
};
4. Update linksβ
Check for other files if there are links require to be updated.
5. Checkβ
yarn start
Your website should be running with your new homepage and docs under /docs
.