Docusaurus follows single-page application conventions for routing: each URL corresponds to exactly one React component. That component is bundled separately and only loaded when the user navigates to its route. The routing layer is powered by React Router, but Docusaurus adds a static site generation pass on top so that every route also exists as a pre-rendered HTML file on disk.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/facebook/docusaurus/llms.txt
Use this file to discover all available pages before exploring further.
Routing in content plugins
Every content plugin provides arouteBasePath option that controls where its routes are mounted in the URL tree. The defaults are:
| Plugin | Default routeBasePath |
|---|---|
@docusaurus/plugin-content-docs | /docs |
@docusaurus/plugin-content-blog | /blog |
@docusaurus/plugin-content-pages | / |
/docs/advanced/routing first matches the /docs branch (registered by the docs plugin) and then resolves to the individual doc inside that branch.
Pages routing
The pages plugin maps files directly to URLs with no extra configuration.src/pages/index.tsx becomes /; src/pages/about.md becomes /about. The component for Markdown pages is @theme/MDXPage; React pages are used directly as the route component.
Blog routing
The blog plugin creates several route types from a singleblog/ directory:
Post list pages
Post list pages
/blog, /blog/page/2, /blog/page/3 … Paginated with @theme/BlogListPage. The base path is configurable via pageBasePath.Individual post pages
Individual post pages
One route per Markdown post, e.g.
/blog/2024/05/10/my-post. The URL is fully customisable through the slug front matter field. Component: @theme/BlogPostPage.Tag pages
Tag pages
A tags index at
/blog/tags (@theme/BlogTagsListPage) and per-tag listing pages at /blog/tags/my-tag (@theme/BlogTagsPostsPage). Base path configurable via tagsBasePath.Archive page
Archive page
A chronological listing of all posts at
/blog/archive. Component: @theme/BlogArchivePage. Base path configurable via archiveBasePath.Docs routing and nested routes
The docs plugin is the only built-in plugin that creates nested routes. It registers a top-level version route (e.g./docs/, /docs/next/, /docs/2.0.0/) rendered by @theme/DocPage. Individual docs are rendered inside that layout by @theme/DocItem. This nesting keeps the sidebar and version context alive as the user moves between docs pages without a full page reload.
slug front matter customises the final segment of a doc’s URL but cannot override the version base path set by routeBasePath.
File paths vs. URL paths
Docusaurus distinguishes between file paths (references to files on disk) and URL paths (addresses in the browser). When you write a link in Markdown, Docusaurus uses these heuristics to decide which kind it is:- URL paths
- File paths
- Starts with
http://orhttps://— always an external URL. - Has no file extension — treated as a URL path.
[page](../plugins)on/docs/advanced/routinglinks to/docs/plugins. Broken-link detection runs at build time, not at author time.
Sample file-to-URL mapping
Routes become HTML files
Because Docusaurus is a static site generator, every registered route is pre-rendered to an HTML file duringdocusaurus build. The URL /docs/advanced/routing maps to the file build/docs/advanced/routing/index.html. This is the file served when a user first loads the page; the browser then hydrates it into a full SPA.
If
trailingSlash: false is set in docusaurus.config.js, the output file is routing.html rather than routing/index.html. Some hosting providers treat these differently — see the trailing slash guide for details.baseUrl must be correct. If your site is deployed under https://example.com/myproject/, set baseUrl: '/myproject/' so that asset URLs resolve correctly.
Generating and accessing routes
Plugins register routes using theaddRoute action inside contentLoaded. All registered routes are aggregated into .docusaurus/routes.js, which you can inspect via the debug plugin’s routes panel (available at /__docusaurus/debug/routes in development).
my-plugin/index.js
Code splitting
Each route’s component and its prop modules are code-split automatically. Webpack emits a separate chunk for each route so that the browser only downloads what it needs for the current page. On navigation, Docusaurus preloads the next route’s chunk while the current page is still displayed, making transitions feel instant.Accessing the current route in components
On the client side, use@docusaurus/router (a re-export of react-router-dom v5) to read the current location. This API is SSR-safe, unlike window.location.
src/components/CurrentPath.jsx
useLocation with useDocusaurusContext:
src/components/BreadcrumbBar.jsx
Escaping SPA redirects
Docusaurus is a single-page application: internal navigations usehistory.push() and never cause a full page reload. If you place an HTML file in static/, it is copied to the build output but is not part of the React Router route tree. Linking to it with a normal Markdown link causes the SPA router to intercept the click and show a 404.
Use the pathname:// protocol to opt out of SPA navigation for a specific link:
pathname:// prefix and emits a plain <a href="/my-static-page.html"> that the browser follows with a full navigation.