在 netlify 上部署 React 应用程序后 HTTP GET 响应 304 状态错误

HTTP GET response 304 status error after deploying react app on netlify

_redirects

/*     /index.html   200!

packagae.json

"scripts" : {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  }

如果您要将 _redirects 放入 create react app,它应该放入 public 文件夹。 build 文件夹不应该在你的存储库中,用于像 Netlify 这样的连续构建解决方案。

您在此处建议的 _redirects 通常用于当您将单页应用程序与路由器(如 React 路由器)一起使用并希望路径始终转到 index.html 当它不存在时。您不希望它解析资产价值路径。

This redirect rule will serve the index.html instead of giving a 404 no matter what URL the browser requests.

_redirects

/*    /index.html   200

发生的事情是您强制 index.html 页面提供服务,即使没有有效路径,您的资产也会发生这种情况。

  • 修复
  • _redirects 移动到 public 文件夹
  • 从重定向的末尾删除 !,因此如果找到路径,它会正确地提供它,而不是总是强制它到 index.html