简体   繁体   English

反应 - 在反应应用程序上刷新页面不起作用

[英]React - Doesn't work refreshing page on react app

I am building front-end of marketplace using react.我正在使用 react 构建市场的前端。 "react": "^17.0.2" "react-redux": "^7.2.5" "react-scripts": "4.0.3" @reach/router": "^1.3.4" "react": "^17.0.2" "react-redux": "^7.2.5" "react-scripts": "4.0.3" @reach/router": "^1.3.4"

After built the app on local or netlify, when refreshing page(F5), it doesn't work and it returns blank page.在本地或netlify上构建应用程序后,刷新页面(F5)时,它不起作用并返回空白页面。 In details, "404: The requested path could not be found" on local, and then blank page with console error on netlify.详细地说,“404:找不到请求的路径”在本地,然后是 netlify 上出现控制台错误的空白页面。

But, it does work well on local dev(yarn start) and from clicking menu after built.但是,它在本地开发(纱线启动)和构建后单击菜单上运行良好。

I had already tried to add "homepage":"."我已经尝试添加“主页”:“。” on package.json and _redirects file with /* /index.html 200 on root and build folder.在 package.json 和_redirects文件上,在根目录和构建文件夹上使用/* /index.html 200

I am not sure whether it is build setting problem or @reach/router issue.我不确定是构建设置问题还是@reach/router 问题。

How can I fix this issue?我该如何解决这个问题?

Hope to your quick help.希望对您的快速帮助。

Thank you,谢谢,

PS: Attached my issue screenshots. PS:附上我的问题截图。

Error on local本地错误

Error on netlify netlify 上的错误

create a .htaccess file in the public directory of your react project and paste the text below.在你的 react 项目的公共目录中创建一个.htaccess文件并粘贴下面的文本。

Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]

When built again and re-uploaded it should not have an error on reload.再次构建并重新上传时,重新加载时不应出现错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM