docusaurus默认访问地址前缀 以及多实例

前言

默认情况下 所有的md文档 都应该以docs为根目录。

you-project
 |--docs
    |--test.md

而访问路由 也是默认的http://localhost:3000/docs/test

如果觉得不好看 需要修改路由前缀 为http://localhost:3000/guide/test
则需要修改如下

const config = {
  ...
  presets: [
    [
      'classic',
      ({
        docs: {
          ...
          routeBasePath: "guide",
        },
        ...
      }),
    ],
  ],

多个实例下

修改配置文件docusaurus.config.js
可以根据如上只是 并且结合@docusaurus/plugin-content-docs来实现

you-project
 |--docs
    |--guide
      |--- 第一章.md
    |--- api
      |--- 第一章.md
const config = {
  ...
  plugins: [
...
  "@docusaurus/plugin-content-docs",
    {
      id: 'api-module',
      path: 'docs/api',
      routeBasePath: 'api',
      sidebarPath: require.resolve("./sidebars.js"),
    }
],
  presets: [
    [
      'classic',
      ({
        docs: {
          sidebarPath: require.resolve('./sidebars.js'),
          path: "docs/guide",
          routeBasePath: "guide",
        },
        ...
      }),
    ],
  ]

};

module.exports = config;

如上 只是路由能够访问了 但如果需要配置到顶部菜单中 则还需要再配置文件中修改如下

themeConfig:
    ({
      ...
        items: [
          {
            type: 'doc',
            docId: '第1章_前言',
            label: '文档',
          },
          {
            docsPluginId: 'api-module',
            type: 'doc',
            docId: '第1章_前言',
            label: 'API',
          }
        ],
      },
      ...
    })
posted @ 2023-01-30 16:21  丁少华  阅读(134)  评论(5编辑  收藏  举报