在这个URL中,您可以看到这个问题:http://qconstruct.in/contact
这是代码沙箱中的代码链接:https://codesandbox.io/s/upbeat-hypatia-3pre9,看起来输出在代码沙箱中运行得很好。但是,在刷新其他路由页面之后,我的托管网站就不能工作了。
我使用React路由器引导
import { BrowserRouter as Router, Route, Switch } from "react-router-dom";
import { LinkContainer } from 'react-router-bootstrap';
import { Navbar, Nav, NavItem } from 'react-bootstrap';发布于 2020-04-12 14:53:15
这个问题在服务器端。
参考以下链接:https://tylermcginnis.com/react-router-cannot-get-url-refresh/
我的主机中有appache服务器,所以我在我的网站的根路径中的".htaccess“文件中添加了下面的代码。
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]起作用了!谢谢大家的帮助。
发布于 2020-04-06 13:41:37
尝试在构建的根目录中添加.htaccess文件
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html [L]
</IfModule>
https://stackoverflow.com/questions/61010521
复制相似问题