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
相关产品推荐
相关产品推荐

