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

Firebase托管Angular SPA:根路径返回静态欢迎页配置问题

正确的Firebase托管重写配置方案

问题根源:开启i18n时,默认的redirectToDefaultLocale: true会将根路径请求自动重定向到默认语言路径(比如/en/),导致你的根路径重写规则从未被触发。

修正后的完整配置:

{
  "hosting": {
    ...,
    "rewrites": [
      {
        "source": "/",
        "destination": "/en/welcome.html"
      },
      {
        "source": "/es/**",
        "destination": "/es/index.html"
      },
      {
        "source": "**",
        "destination": "/en/index.html"
      }
    ],
    "i18n": {
      "root": "/",
      "defaultLocale": "en",
      "redirectToDefaultLocale": false
    }
  },
  ...
}

关键说明:

  • 添加redirectToDefaultLocale: false,关闭Firebase对根路径的自动语言重定向,确保根路径请求直接匹配第一条重写规则。
  • 保持重写规则的顺序:根路径规则优先级最高,其次是西班牙语路径,最后匹配所有其他路径(包括英语子路径)。
  • 确保/en/welcome.html文件存在于你的托管资源目录中(比如Angular项目的dist/[project-name]/en/下)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.14 00:01:07