获取 404-Page Not Found 错误,当我重新加载我在 firebase 上的反应应用程序时

Getting 404-Page Not Found error, when i reload my react application which is on firebase

我已经在 firebase 上部署了我的 React 应用程序,当我重新加载页面时,它显示了以下页面。

Firebase.json

{
  "hosting": {
    "public": "build",
    "ignore": ["firebase.json", "**/.*", "**/node_modules/**"]
  }
}

不是单页应用程序

添加以下 rewrites 规则:

"hosting": {
    "public": "build",
    "ignore": [
        "firebase.json",
        "**/.*",
        "**/node_modules/**"
    ],
    "rewrites": [
        {
            "source": "**",
            "destination": "/index.html"
        }
    ]
}

这将确保 Firebase 将为请求的任何路由提供您的 React 应用程序。

firebase.json 文件中添加 'rewrite' 规则。 您的 firebase.json 文件应如下所示:

{
  "firestore": {
    "rules": "firestore.rules",
    "indexes": "firestore.indexes.json"
  },
  "hosting": {
    "public": "build",
    "ignore": ["firebase.json", "**/.*", "**/node_modules/**"],
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}