【问题标题】:Angular routing not working i firebase hostingAngular 路由在 Firebase 托管中不起作用
【发布时间】:2020-03-22 00:06:23
【问题描述】:

我有一个 Angular 项目,其中路由在 localhost 中工作,但是当我将项目部署到 Firebase 托管时,只有 base-url 工作。 这是我的路由:示例 https://baseurl/jegharaldrigkategori 在 Firbase 托管中不起作用。它说“找不到页面”

  const routes: Routes = [
  {
      path: '',
      redirectTo: 'home', 
      pathMatch: 'full'
  },
  {
    path: 'home', 
    component: HomeComponent
  },
  {
    path: 'jegharaldrigkategori', 
    component: JegharaldrigkategoriComponent
  },
  {
    path: 'jegharaldrig', 
    component: JegharaldrigComponent
  },
  {
    path: 'udfordring', 
    component: UdfordringComponent
  },
  {
    path: 'terning', 
    component: TerningComponent
  },
  {
    path: 'overunder', 
    component: OverunderComponent
  }
];

【问题讨论】:

  • 您的firebase.json 配置是什么样的?是否设置为为所有路径提供index.html

标签: angular typescript firebase angular-routing firebase-hosting


【解决方案1】:

在 Firebase 上托管时,您必须记住将所有呼叫重定向到 index.html

firebase.json 的托管部分应包括“重写”,这是一个示例:

"hosting": {
    "public": "public",
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  },

【讨论】:

  • 我遇到了同样的错误。我在firebase.json 中执行了此操作,并且没有显示 firebase 404 页面。但是现在我的主题的 404 错误页面正在打开。但在我的路线中有一个有效的 URL。有什么解决办法吗?
猜你喜欢
  • 2020-07-14
  • 2017-03-28
  • 2021-11-04
  • 1970-01-01
  • 2018-10-25
  • 1970-01-01
  • 2013-09-24
  • 2018-10-20
  • 1970-01-01
相关资源
最近更新 更多