react项目部署在windows服务器上时,使用IIS来部署,部署完成后打开响应ip+port没有报错,在相应页面点击刷新会出现这样的错误
解决办法:在项目根目录的web.config文件中使用下面一段代码即可(如果没有web.config可以手动创建一个)
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="ReactRouter" patternSyntax="ECMAScript" 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>
</system.webServer>
</configuration>
有的文章使用URL重写进行配置相关内容是一样的道理,使用URL重写配置之后也会自动生成相应的web.config