如果配置为 `trailingSlash: true`,如何为 Next.js + GitHub 页面设置自定义 404 页面

How to have custom 404 page for Next.js + GitHub Pages if config is `trailingSlash: true`

我有一个使用 Next.js 构建的静态网站,目前部署在 GitHub 个页面中。我已经在 Next.js 中创建了一个自定义 404 页面,其配置 trailingSlash: true 将其置于此目录 /404/index.html 下。在 GitHub 页面的文档 here 中看到我可以使用可以读取永久链接的 404.md,我假设这意味着我的自定义 404 页面的路径。所以我在部署分支的根文件夹中创建了一个。

---
permalink: /404/index.html
---

但似乎没有用。我想知道我是否假设或做错了什么。另请注意,我的 GitHub 页面已在自定义域下。请建议是否有其他方法但仍保留 trailingSlash: true 配置,因为我不想在我的其他静态页面的路由上显示 .html。先谢谢你了。

最后,我没有使用 404.md,只是在我的 ci/cd GitHub 操作工作流程中添加了一个步骤来移动生成的 404 页面并将其重命名为 404.html GitHub 页面将理解为我的自定义 404 页面。

jobs:
  build:
    ...
    steps:
    ...
      - name: Generate static files
        run: yarn export

      - name: Move 404 page to root directory
        run: mv ./out/404/index.html ./out/404.html