Thanh bên
We have introduced three types of item types in the example in the previous section: doc, category, and link, whose usages are fairly intuitive. We will formally introduce their APIs. There's also a fourth type: autogenerated, which we will explain in detail later.
- Doc: link to a doc page, associating it with the sidebar
- Link: link to any internal or external page
- Category: creates a dropdown of sidebar items
- Autogenerated: generate a sidebar slice automatically
- HTML: renders pure HTML in the item's position
- *Ref: link to a doc page, without making the item take part in navigation generation
Doc: link to a doc
Use the doc type to link to a doc page and assign that doc to a sidebar:
type SidebarItemDoc =
// Normal syntax
| {
type: 'doc';
id: string;
label: string; // Sidebar label text
className?: string; // Class name for sidebar label
customProps?: Record<string, unknown>; // Custom props
}
// Shorthand syntax
| string; // docId shortcut
Example:
sidebars.js
export default {
mySidebar: [
// Normal syntax:
{
type: 'doc',
id: 'doc1', // document ID
label: 'Getting started', // sidebar label
},
// Shorthand syntax:
'doc2', // document ID
],
};
If you use the doc shorthand or autogenerated sidebar, you would lose the ability to customize the sidebar label through item definition. You can, however, use the sidebar_label Markdown front matter within that doc, which has higher precedence over the label key in the sidebar item. Similarly, you can use sidebar_custom_props to declare custom metadata for a doc page.
note
A doc item sets an implicit sidebar association. Don't assign the same doc to multiple sidebars: change the type to ref instead.
tip
Sidebar custom props is a useful way to propagate arbitrary doc metadata to the client side, so you can get additional information when using any doc-related hook that fetches a doc object.
Link: link to any page
Chúng tôi đã giới thiệu ba loại mục trong ví dụ trong phần trước: , và , có cách sử dụng khá trực quan. Chúng tôi sẽ chính thức giới thiệu API của họ. Ngoài ra còn có một loại thứ tư: , mà chúng tôi sẽ giải thích chi tiết sau.doc``category``link``autogenerated
- Tài liệu: liên kết đến trang tài liệu, liên kết trang đó với thanh bên
- Liên kết: liên kết đến bất kỳ trang nội bộ hoặc bên ngoài nào
- Danh mục: tạo danh sách thả xuống các mục thanh bên
- Tự động tạo: tự động tạo lát cắt thanh bên
- HTML: hiển thị HTML thuần túy ở vị trí của mục
- *Tham chiếu: liên kết đến trang tài liệu, mà không làm cho mục tham gia vào việc tạo điều hướng