/docs 中所有页面上的简短 HTTP 404 错误

发布于 2025-01-18 12:05:32 字数 3423 浏览 3 评论 0原文

我最近第一次部署了 Docusaurus 站点,但遇到了一个奇怪的路由问题。

/docs 文件夹中的每个页面在直接点击页面时都会短暂呈现 404.html 页面。但是,如果我在侧边栏中单击,页面就会正确呈现。

这只发生在 /docs 文件夹中。如果我单击主页链接,我不会看到 404。

我无法在本地复制此问题。我尝试了yarn startyarn build/serve,在这两种情况下,应用程序都运行良好。我没有看到任何 404、控制台错误等。404 的响应负载是 OOTB Docusaurus 页面,我没有对其进行任何自定义或处理方式。

附件是一个显示行为的 gif 和一个屏幕截图,显示浏览器在我的非本地主机环境中看到硬 404。

输入图片此处描述

在此处输入图像描述

这是我的配置文件:

// @ts-check
// Note: type annotations allow type checking and IDEs autocompletion

const lightCodeTheme = require('prism-react-renderer/themes/github');
const darkCodeTheme = require('prism-react-renderer/themes/dracula');

/** @type {import('@docusaurus/types').Config} */
const config = {
    title: 'Guidebook',
    tagline: 'Engineering Information',
    url: 'https://guidebook.our-internal-domain.tools/',
    baseUrl: '/',
    onBrokenLinks: 'throw',
    onBrokenMarkdownLinks: 'throw',
    favicon: 'img/favicon.png',
    organizationName: 'Guidebook',
    projectName: 'Guidebook',

    presets: [
        [
            'classic',
            /** @type {import('@docusaurus/preset-classic').Options} */
            ({
                docs: {
                    sidebarPath: require.resolve('./sidebars.js'),
                    editUrl: 'https://git.our-internal-domain.com/tech-standards/tech-guidebook'
                },
                blog: false,
                theme: {
                    customCss: require.resolve('./src/css/custom.css')
                }
                // debug: true
            })
        ]
    ],
    themeConfig: {
        navbar: {
            title: 'Home',
            logo: {
                alt: 'Home',
                src: 'img/TechnologyGuidebook-Icon_Red_Small.svg'
            },
            items: [
                {
                    type: 'doc',
                    docId: 'intro',
                    position: 'left',
                    label: 'Guidebook'
                },
                {
                    href: 'https://git.our-internal-domain.com/tech-standards/tech-guidebook',
                    label: 'GitHub',
                    position: 'right'
                }
            ]
        },
        footer: {
            style: 'dark',
            links: [
                {
                    title: 'Community',
                    items: [
                        {
                            label: 'Stack Overflow',
                            href: 'https://stackoverflow.com/questions/tagged/docusaurus'
                        }
                    ]
                },
                {
                    title: 'More',
                    items: [
                        {
                            label: 'GitHub',
                            href: 'https://github.com/facebook/docusaurus'
                        }
                    ]
                }
            ],
            copyright: `Copyright © ${new Date().getFullYear()} Guidebook V2, Inc. Built with Docusaurus.`
        },
        prism: {
            theme: lightCodeTheme,
            darkTheme: darkCodeTheme
        }
    }
};

module.exports = config;

I recently deployed our Docusaurus site for the first time and I am running into a weird issue with routing.

Every page in the /docs folder will briefly render the 404.html page when hitting the page directly. However, if I click around in sidebar the pages render properly.

This only happens in the /docs folder. If I click on the home page link I do not see the 404.

I cannot replicate this issue locally. I have tried both yarn start and yarn build/serve and in both cases the app works fine. I do not see any 404s, console errors, etc. The response payload of the 404 is the OOTB Docusaurus page, I have not done any customization to it or how its handled.

Attached is a gif showing the behavior and a screen shot showing that the browser is seeing a hard 404 in my non-localhost environment.

enter image description here

enter image description here

And here's my config file:

// @ts-check
// Note: type annotations allow type checking and IDEs autocompletion

const lightCodeTheme = require('prism-react-renderer/themes/github');
const darkCodeTheme = require('prism-react-renderer/themes/dracula');

/** @type {import('@docusaurus/types').Config} */
const config = {
    title: 'Guidebook',
    tagline: 'Engineering Information',
    url: 'https://guidebook.our-internal-domain.tools/',
    baseUrl: '/',
    onBrokenLinks: 'throw',
    onBrokenMarkdownLinks: 'throw',
    favicon: 'img/favicon.png',
    organizationName: 'Guidebook',
    projectName: 'Guidebook',

    presets: [
        [
            'classic',
            /** @type {import('@docusaurus/preset-classic').Options} */
            ({
                docs: {
                    sidebarPath: require.resolve('./sidebars.js'),
                    editUrl: 'https://git.our-internal-domain.com/tech-standards/tech-guidebook'
                },
                blog: false,
                theme: {
                    customCss: require.resolve('./src/css/custom.css')
                }
                // debug: true
            })
        ]
    ],
    themeConfig: {
        navbar: {
            title: 'Home',
            logo: {
                alt: 'Home',
                src: 'img/TechnologyGuidebook-Icon_Red_Small.svg'
            },
            items: [
                {
                    type: 'doc',
                    docId: 'intro',
                    position: 'left',
                    label: 'Guidebook'
                },
                {
                    href: 'https://git.our-internal-domain.com/tech-standards/tech-guidebook',
                    label: 'GitHub',
                    position: 'right'
                }
            ]
        },
        footer: {
            style: 'dark',
            links: [
                {
                    title: 'Community',
                    items: [
                        {
                            label: 'Stack Overflow',
                            href: 'https://stackoverflow.com/questions/tagged/docusaurus'
                        }
                    ]
                },
                {
                    title: 'More',
                    items: [
                        {
                            label: 'GitHub',
                            href: 'https://github.com/facebook/docusaurus'
                        }
                    ]
                }
            ],
            copyright: `Copyright © ${new Date().getFullYear()} Guidebook V2, Inc. Built with Docusaurus.`
        },
        prism: {
            theme: lightCodeTheme,
            darkTheme: darkCodeTheme
        }
    }
};

module.exports = config;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空心↖ 2025-01-25 12:05:32

我正在使用 Vercel 部署 Docusaurus V2 网站,但在重定向方面遇到了同样的问题。

通过在我的 vercel 中启用 cleanUrls 修复了此问题.json 配置。

I am using Vercel to deploy a Docusaurus V2 website and was running into the same issue with redirects.

Fixed this issue by enabling cleanUrls inside my vercel.json config.

稚气少女 2025-01-25 12:05:32

我想通了。这不是 Docusaurus 的问题。问题是我们的 CloudFront 基础设施中的配置问题。

I figured it out. It wasn't a Docusaurus problem. The problem was a configuration issue in our CloudFront infrastructure.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文