在 netlify 上部署 React 应用程序后 HTTP GET 响应 304 状态错误
HTTP GET response 304 status error after deploying react app on netlify
- 我在 netlify 中部署了 React 应用程序
- 所以我使用 npm 运行 构建命令来构建本地脚本并在 netlify 中手动部署应用程序用于生产模式
- 构建脚本正在本地机器上创建并上传到 netlify 站点
- 显示消息部署成功
- 点击 URL link,之前显示 GET 构建脚本请求的状态为 404
- 在构建文件夹中包含重定向文件后,它的状态更改为 GET 构建脚本请求为 304,并显示错误为
syntax error: uncaught error : unexpected token <
- 为了调试,我注释了文件和 运行 找出错误的代码
- 但是,无法找到根源错误
- 你们能帮我解决一下我的建议吗
- netlify URL link: https://lucid-shaw-bb2b3f.netlify.com
- 应用程序代码在 github 及其 link 中可用:https://github.com/aarivalagan/react-one
- 下面附上应用程序截图
- 提供以下代码片段:
_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
- 我在 netlify 中部署了 React 应用程序
- 所以我使用 npm 运行 构建命令来构建本地脚本并在 netlify 中手动部署应用程序用于生产模式
- 构建脚本正在本地机器上创建并上传到 netlify 站点
- 显示消息部署成功
- 点击 URL link,之前显示 GET 构建脚本请求的状态为 404
- 在构建文件夹中包含重定向文件后,它的状态更改为 GET 构建脚本请求为 304,并显示错误为
syntax error: uncaught error : unexpected token <
- 为了调试,我注释了文件和 运行 找出错误的代码
- 但是,无法找到根源错误
- 你们能帮我解决一下我的建议吗
- netlify URL link: https://lucid-shaw-bb2b3f.netlify.com
- 应用程序代码在 github 及其 link 中可用:https://github.com/aarivalagan/react-one
- 下面附上应用程序截图
- 提供以下代码片段:
_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