React开发中react-route-dom使用BrowserRouter部署到服务器上刷新时报404的问题

React项目部署中遇到的问题

  1. react开发中react-route使用BrowserRoute路径在iis服务器上刷新时报404的问题
    解决:在发布的项目根目录添加web.config配置文件 在配置文件中system.webServer节点中加入
<rewrite>
      <rules>
     <rule name="Rewrite Text Requests" stopProcessing="true">
   	<match url=".*" />
   	<conditions>
   		<add input="{HTTP_METHOD}" pattern="^GET$" />
   		<add input="{HTTP_ACCEPT}" pattern="^text/html" />
   		<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
   	</conditions>
   	<action type="Rewrite" url="/index.html" />
     </rule>
      </rules>
</rewrite>

2.nginx服务器上刷新时报404的问题
解决:修改nginx.conf内容

location / {
    ...
	
    try_files $uri $uri/ /index.html;
}
posted @ 2021-06-17 09:22  hello_xier  阅读(389)  评论(0编辑  收藏  举报