Sidebar
Creating a sidebar is useful to:
- Group multiple related documents
- Display a sidebar on each of those documents
- Provide a paginated navigation, with next/previous button
To use sidebars on your Docusaurus site:
- Define a file called
sidebar.jsthat exports a sidebar object. - Pass this object into the
@docusaurus/plugin-docsplugin directly or via@docusaurus/preset-classic.
Default sidebar#
You can also define your sidebars explicitly.
Sidebar objects#
A sidebar is a tree of sidebar items.
A sidebars file can contain multiple sidebar objects.
Example:
Notice the following:
- There is a single sidebar mySidebar, containing 5 sidebar items
Getting StartedandDocusaurusare sidebar categoriesdoc1,doc2anddoc3are sidebar documents
TIP
Use the shorthand syntax to express this sidebar more concisely:
Using multiple sidebars#
You can create a sidebar for each set of markdown files that you want to group together.
TIP
The Docusaurus site is a good example of using multiple sidebars:
- Docs
- API
Example:
NOTE
The keys tutorialSidebar and apiSidebar are sidebar technical ids and do not matter much.
When browsing:
- doc1 or doc2: the
tutorialSidebarwill be displayed - doc3 or doc4: the
apiSidebarwill be displayed A paginated navigation link documents inside the same sidebar with next and previous buttons.
Sidebar Items#
SidebarItem is an item defined in a Sidebar tree.
There are different types of sidebar items:
- Doc: link to a doc page, assigning it to the sidebar
- Ref: link to a doc page, without assigning it to the sidebar
- Link: link to any internal or external page
- Category: create a hierarchy of sidebar items
- Autogenerated: generate a sidebar slice automatically
Doc: link to a doc#
Use the doc type to link to a doc page and assign that doc to a sidebar:
Example:
The sidebar_label markdown frontmatter has a higher precedence over the label key in SidebarItemDoc.
:::into note
Don't assign the same doc to multiple sidebars: use a ref instead. :::
Ref: link to a doc, without sidebar#
Use the ref type to link to a doc page without assigning it to a sidebar.
Example:
When browsing doc1, Docusaurus will not display the mySidebar sidebar.
Link: link to any page#
Use the link type to link to any page (internal or external) that is not a doc.
Example:
Category: create a hierarchy#
Use the category type to create a hierarchy of sidebar items.
Example:
For more usages, see documentation.