You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docusaurus中createRedirects无法实现/docs路径重定向求助

Docusaurus 仅文档模式批量重定向问题修复

你的代码核心问题是搞反了createRedirects的逻辑方向,同时判断条件完全错误:

  • existingPath参数代表的是当前已存在的新路径(比如迁移后的/pricing),而非旧的/docs/pricing路径
  • 当前代码逻辑是试图从新路径重定向到新路径(替换后路径完全不变),根本起不到将旧路径导向新路径的作用

修正后的代码

createRedirects(existingPath) {
  // 为每个根路径页面,创建从旧路径/docs/xxx到新路径/xxx的重定向
  return [`/docs${existingPath}`];
}

补充说明

  • 无需额外判断includes('/'):首页路径/会自动生成/docs/到/的重定向,完全符合迁移需求
  • 如果有个别页面不需要重定向,可添加条件排除,示例如下:
    createRedirects(existingPath) {
      // 排除不需要重定向的页面
      if (existingPath === '/exclude-this-page') {
        return undefined;
      }
      return [`/docs${existingPath}`];
    }
    

内容的提问来源于stack exchange,提问作者NoSQLKnowHow

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 14:10:28