如何为 angular 应用禁用 firebase 的 404 页面

How to disable firebase's 404 page for an angular app

我有一个 angular 应用程序,它使用 firebase 部署到生产环境。

该应用包含以下重定向

const routes: Routes = [
  { path: '', component: HomeComponent },
  // some others
  { path: '**', redirectTo: '/' },
];

在本地环境中,这按要求工作,未定义的路径被重定向 -> HomeComponent 可见。

但是,在部署的应用程序中,用户被重定向到 firebase 404 页面

如何禁用 firebase 页面,以便用户在尝试访问不存在的页面时看到 HomeComponent?

听起来您想将 Firebase 托管配置为将所有 URL 提供给单个 HTML 文件,通常 index.html 在部署的根目录中。在这种情况下,您需要按照 documentation:

中的描述在您的 firebase.json 中添加它
"hosting": {
  "rewrites": [ {
    "source": "**",
    "destination": "/index.html"
  } ]
}

另请参阅: