微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用Docusaurus v2创建新的文档页面

如何解决使用Docusaurus v2创建新的文档页面

我正在尝试Docusaurus v2,我希望有两个不同的文档页面一个用于文档,一个用于API。

这是我的文件结构:

docusaurus.config.js

module.exports = {
  title: 'My Site',tagline: 'The tagline of my site',url: 'https://your-docusaurus-test-site.com',baseUrl: '/',onbrokenLinks: 'throw',favicon: 'img/favicon.ico',organizationName: 'facebook',// Usually your GitHub org/user name.
  projectName: 'docusaurus',// Usually your repo name.
  themeConfig: {
    navbar: {
      title: 'My Site',logo: {
        alt: 'My Site logo',src: 'img/logo.svg',},items: [
        {
          to: 'docs/documentation',activeBasePath: 'docs',label: 'Documentation',position: 'left',{
          to: 'docs/api',label: 'API',{ to: 'blog',label: 'Blog',position: 'left' },{
          href: 'https://github.com/facebook/docusaurus',label: 'GitHub',position: 'right',],footer: {
      style: 'dark',links: [
        {
          title: 'Docs',items: [
            {
              label: 'Style Guide',to: 'docs/',{
              label: 'Second Doc',to: 'docs/doc2/',{
          title: 'Community',items: [
            {
              label: 'Stack Overflow',href: 'https://stackoverflow.com/questions/tagged/docusaurus',{
              label: 'discord',href: 'https://discordapp.com/invite/docusaurus',{
              label: 'Twitter',href: 'https://twitter.com/docusaurus',{
          title: 'More',items: [
            {
              label: 'Blog',to: 'blog',{
              label: 'GitHub',href: 'https://github.com/facebook/docusaurus',copyright: `copyright © ${new Date().getFullYear()} My Project,Inc. Built with Docusaurus.`,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/',blog: {
            showReadingTime: true,// Please change this to your repo.
            editUrl: 'https://github.com/facebook/docusaurus/edit/master/website/blog/',theme: {
            customCss: require.resolve('./src/css/custom.css'),}

sidebars.js

module.exports = {
  documentation: {
    Example: ['documentation/documentation1'],// Docusaurus: ['doc1','doc2','doc3'],// Features: ['mdx'],api: {
    'Color formats': ['api/api1'],}

documentation1.md

---
id: documentation1
title: Documentation 1
sidebar_label: Style Guide
slug: /
---

...

api1.md

---
id: api1
title: Api 1
sidebar_label: Style Guide
slug: /
---

...

但是它不起作用。当我单击“文档”按钮时,它转到localhost:3000/docs/documentation,我得到Page Not Found。当我单击API按钮时,它转到localhost:3000/docs/api,并且出现相同的错误。 如果我转到/localhost:3000/docs/,则会看到api1 markdown文件内容

我也收到此警告:

warn Duplicate routes found!
Attempting to create page at /docs/,but a page already exists at this route
Attempting to create page at /docs/,but a page already exists at this route
This Could lead to non-deterministic routing behavior

我做错了什么?

我只是想拥有一个链接Documentation的按钮/documentation一个链接/api的按钮API。

我想我必须在这里进行一些修改,但是我不知道什么:

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/',blog: {...},theme: {...},

我阅读了documentation,并在Google上进行了搜索,但没有任何帮助。

解决方法

默认情况下,所有文档都在/ docs /路径下。侧边栏不会影响路线。

您创建了2个文档,这些文档具有slug,因此它们的最终路径都是/ docs/。

您应该使用slug:/ api并链接到/ docs / api

如果您真的想要/ api,则有一个仅用于删除/ docs /路径前缀的docs选项

,

秘诀就是使用docusarus config中的doc类型,并设置

activeSidebarClassName: 'navbar__link--active',

https://docusaurus.io/docs/api/themes/configuration#navbar-doc-link

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。