Angular app部署到firebase:404错误

时间:2018-05-26 17:03:52

标签: angular firebase deployment hosting google-cloud-firestore

我正在尝试将我的角度应用部署到Firebase。

当我这样做时,我会转到托管网址,并且我收到了大量404错误(runtime.js,build.js等等)和一个空白页面

我不明白为什么,我做了:

firebase init

chose storage/firestore/hosting

ng build

firebase deploy

当我做firebase服务时,它正在工作......这很奇怪

(ps:angular 6.0.3,firebase 5.0.4)

我的firebase.json(我必须添加/ hello我的项目名称,因为ng build in dist / hello - &gt;&#34; outputPath&#34;:&#34; dist / hello&#34;,)< / p>

{
  "firestore": {
    "rules": "firestore.rules",
    "indexes": "firestore.indexes.json"
  },
  "functions": {
    "predeploy": [
      "npm --prefix \"$RESOURCE_DIR\" run lint",
      "npm --prefix \"$RESOURCE_DIR\" run build"
    ],
    "source": "functions"
  },
  "hosting": {
    "public": "dist/hello",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ]
  },
  "storage": {
    "rules": "storage.rules"
  }
}

1 个答案:

答案 0 :(得分:1)

您应该设置rewrites以确保它应该将所有网址重写为index.html。

 {
      "firestore": {
        "rules": "firestore.rules",
        "indexes": "firestore.indexes.json"
      },
      "functions": {
        "predeploy": [
          "npm --prefix \"$RESOURCE_DIR\" run lint",
          "npm --prefix \"$RESOURCE_DIR\" run build"
        ],
        "source": "functions"
      },
      "hosting": {
        "public": "dist/hello",
        "ignore": [
          "firebase.json",
          "**/.*",
          "**/node_modules/**"
        ]
    "rewrites": [
          {
            "source": "**",
            "destination": "/index.html"
          }
        ]
      },
      "storage": {
        "rules": "storage.rules"
      }
    }