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.js
that exports a sidebar object. - Pass this object into the
@docusaurus/plugin-docs
plugin directly or via@docusaurus/preset-classic
.
#
Default sidebarYou can also define your sidebars explicitly.
#
Sidebar objectsA 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 Started
andDocusaurus
are sidebar categoriesdoc1
,doc2
anddoc3
are sidebar documents
TIP
Use the shorthand syntax to express this sidebar more concisely:
#
Using multiple sidebarsYou 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
tutorialSidebar
will be displayed - doc3 or doc4: the
apiSidebar
will be displayed A paginated navigation link documents inside the same sidebar with next and previous buttons.
#
Sidebar ItemsSidebarItem 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 docUse 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 sidebarUse 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 pageUse the link type to link to any page (internal or external) that is not a doc.
Example:
#
Category: create a hierarchyUse the category
type to create a hierarchy of sidebar items.
Example:
For more usages, see documentation.