【问题标题】:Deploying React app on Firebase returns 404 pages在 Firebase 上部署 React 应用返回 404 页面
【发布时间】:2022-10-12 21:44:13
【问题描述】:

试图在 firebase 上部署我的 react 应用程序。应用程序被部署,但是当点击链接时,它返回一个 404 页面。

我已经通过 cli 登录到 Firebase。使用firebase init:

? What do you want to use as your public directory? build
? Configure as a single-page app (rewrite all urls to /index.html)? Yes
? Set up automatic builds and deploys with GitHub? No
? File build/index.html already exists. Overwrite? No

使用npm start,应用程序运行完全正常,但是一旦我将npm run build 转换为firebase initfirebase deploy,它会正确返回登录页面,但其他页面以 404 页的形式返回。

Firebase.json:

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

【问题讨论】:

    标签: reactjs firebase firebase-hosting


    【解决方案1】:

    尝试 :

    在“build”文件夹外复制代码index.html 并粘贴到“build”文件夹内的index.html。 (里面一个应该和另一个一样)

    如果它不起作用:

    1 - 删除您的 .firebase 文件夹。并使用firebase init 再次初始化它 并设置相同的配置,然后重新加载网站。

    【讨论】:

      猜你喜欢
      • 2013-08-28
      • 2022-06-16
      • 2020-12-27
      • 1970-01-01
      • 2015-01-01
      • 1970-01-01
      • 2017-10-06
      • 2022-11-19
      • 2020-05-12
      相关资源
      最近更新 更多