我有一个 Angular 应用程序,它通过 Firebase 部署到生产环境。
该应用程序包括以下重定向
const routes: Routes = [
{ path: '', component: HomeComponent },
// some others
{ path: '**', redirectTo: '/' },
];
在本地环境中,这按要求工作,未定义的路径被重定向 - > HomeComponent 可见。
但是,在部署的应用程序上,用户被重定向到 firebase 404 页面
如何禁用 firebase 页面,以便用户在尝试访问不存在的页面时看到 HomeComponent?
听起来您想要配置 Firebase Hosting 以将所有 URL 提供给单个 HTML 文件,通常是部署根目录中的 index.html。在这种情况下,您需要将其包含在 firebase.json 中,如 documentation:
中所述"hosting": {
"rewrites": [ {
"source": "**",
"destination": "/index.html"
} ]
}
我遇到了和你一样的问题,就我而言,它是在开头缺少一个正斜杠,上面写着“目的地”。 我有这个:
"rewrites": [
{
"source": "**",
"destination": "en/index.html"
}
],
更改为:
"rewrites": [
{
"source": "**",
"destination": "/en/index.html"
}
],
现在可以了!我的角度组件“找不到页面”是用于不存在页面的组件。