Angular 应用程序部署到 firebase:404 错误

Angular app deploy to firebase : 404 errors

我正在尝试将我的 angular 应用程序部署到 Firebase。

当我这样做时,我去了主机 URL,我收到大量 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)

my firebase.json(我不得不添加 /hello 我的项目名称,因为 ng build in dist/hello -> "outputPath": "dist/hello",)

{
  "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"
  }
}

您应该设置 rewrites 以确保它应该将所有 url 重写为 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"
      }
    }