问题描述
我正在尝试在 Docusaurus v2 中添加一个新页面,因此我在 navbar
中添加了一个新项目:
module.exports = {
...
themeConfig: {
navbar: {
title: 'My Site: API Documentation',logo: {
alt: 'My Site logo',src: 'img/logo.png',},items: [
{
to: 'docs/',activeBasePath: 'docs',label: 'Docs',position: 'left',{
to: 'references/',activeBasePath: 'references',label: 'References',],...
},presets: [
[
'@docusaurus/preset-classic',{
docs: {
sidebarPath: require.resolve('./sidebars.js'),// Please change this to your repo.
editUrl:
'https://github.com/facebook/docusaurus/edit/master/website/',theme: {
customCss: require.resolve('./src/css/custom.css'),};
问题是当我点击 References 链接时,我被重定向到 http://localhost:3000/references/ 这给了我一个 Page Not Found 页面:
有谁知道我到底需要把 *.md
放在哪里,或者我应该怎么做才能在 /references
中添加一个页面并访问例如http://localhost:3000/references/dymmy_page?
解决方法
有几个选项,需要检查的东西。您希望为 /references 显示的第一页,您可以将以下内容添加到该 Markdown 文件的前端:slug: /
或者您可以更改为使用 docId(我喜欢)。使用 ID 更容易并且不记得哪个文件添加了 slug 到 frontmatter。 docid 是 Markdown 文件中的 id,格式与 sidebars.js 中的 id 一样(文件夹/id)。
例如:
{
type: 'doc',docId: 'folder-if-any/id-of-markdown-file',label: 'References',position: 'left',},
如果你在下拉菜单中添加引用,那么它会是这样的:
{
label: 'Docs',items: [
{
type: 'doc',to: 'docs/folder-if-any/id-of-markdown-file',{
type: 'doc',to: 'docs/some-other-folder/id-of-markdown-file',label: 'Guide',]
},