Autogenerated navigation
In Rspress, you can either declare nav and sidebar in the config file or generate them automatically from _nav.json and _meta.json. We recommend the latter because it keeps the config file concise, supports HMR, and still exposes everything under themeConfig.
Autogenerated navbar/sidebar only works when rspress.config.ts does not define nav or sidebar.
Basic usage
Rspress generates the navbar from _nav.json and the sidebar from _meta.json. The navbar-level _nav.json lives in the docs root, while sidebar-level _meta.json files live in subdirectories under the docs root. For example:
If your site uses i18n, place the navbar-level _nav.json in each language directory:
Global sidebar usage
By default (only _nav.json exists at the root), Rspress generates a separate sidebar for each subdirectory. The sidebar switches automatically based on the currently active nav item. For example, clicking the "Guide" nav item shows the Guide sidebar, and clicking "API" shows the API sidebar:
If you want all pages to share a single global sidebar instead of switching by nav, you can add a _meta.json at the root level of the docs directory (alongside _nav.json).
This approach works better for documentation sites with fewer nav items and a simpler structure. Since the sidebar stays the same regardless of which nav item is active, it is a good fit when you want to organize the whole site under one unified sidebar:
When a root-level _meta.json exists, Rspress will generate a single sidebar (keyed by '/') for all pages, regardless of which nav item is active. The root _meta.json serves as the entry point for the entire sidebar tree, and you can typically organize subdirectories with section headers:
JSON schema type hint
To improve editing for _nav.json and _meta.json, Rspress provides two schema files for IDE hints: @rspress/core/meta-json-schema.json and @rspress/core/nav-json-schema.json.
For example, in VSCode, you can add the following configuration in .vscode/settings.json:
Navbar level config
At the navbar level, _nav.json accepts an array with the same type as the default theme's nav config. For details, see nav config. For example:
Sidebar level config
At the sidebar level, _meta.json accepts an array whose items use the following types:
file
- When the item is a
string, it represents a file. The string is the file name:
The file name may include a suffix or omit it. For example, introduction is resolved as introduction.mdx.
- When the item is an object, it can describe a file, directory, or custom link.
To describe a file, use the following type:
Here, name is the file name with or without a suffix, and label is the file's display name in the sidebar. If label is omitted, Rspress uses the document's H1 title automatically. overviewHeaders controls which headings are shown on the file's overview page; it is optional and defaults to [2]. context adds a data-context attribute to the generated sidebar DOM node; it is optional and omitted by default. For example:
dir
To describe a directory, use the following type:
Here, name is the directory name, label is the directory's display name in the sidebar, collapsible controls whether the directory can be collapsed, and collapsed controls whether it is collapsed by default. overviewHeaders controls which headings are shown on overview pages for files in this directory; it is optional and defaults to [2]. context adds a data-context attribute to the generated sidebar DOM node; it is optional and omitted by default. For example:
To display a document when users click a sidebar directory, create an index.mdx file inside that directory. For example:
This sidebar contains only the getting-started document. When users click the Guide directory, Rspress displays the content of index.mdx.
dir-section-header new
When describing a directory, you can also use dir-section-header. It behaves like "type": "dir" but renders differently in the UI. It is often used at the first level, where the directory title appears as a section header at the same level as files inside the directory.
Type:
divider
To describe a divider, use the following type:
When dashed is true, the divider is dashed. Otherwise, it is solid.
section-header
To describe a section header, use the following type:
Here, label is the section header's display name in the sidebar. For example:
Section headers make it easier to group documents and directories in the sidebar. You can combine them with divider to separate groups more clearly:
custom-link
To describe a custom link, use the following type:
Here, link is the link target and label is the display name in the sidebar. For example:
link supports external links, for example:
You can also use items to create nested custom links, for example:
Complete example
Here is a complete example using the three types above:
No config usage
In some directories, you can omit _meta.json and let Rspress generate the sidebar automatically. This works when the directory contains only documents, no subdirectories, and you do not need a custom document order. For example:
In the guide directory, configure _meta.json as follows:
In the basic directory, you can omit _meta.json; Rspress then generates the sidebar automatically and sorts files alphabetically by file name. To customize the order, prefix file names with numbers:
Tag icons for sidebar and navbar
You can add icons after titles in the sidebar or navbar through the tag config. The value of tag supports SVG tag strings or image URLs.
For detailed usage, see Tag Component.