在 Docusaurus 中找不到页面

问题描述

我正在尝试在 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 页面

enter image description here

有谁知道我到底需要把 *.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',]
        },

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...