reactjs react应用程序使用IIs发布,react路由器不工作

5jdjgkvh  于 9个月前  发布在  React
关注(0)|答案(1)|浏览(99)

我发布了一个React应用程序在Windows服务器上与IIS,但当我试图刷新页面与F5在我的应用程序这个错误出来:HTTP错误404.0 -您正在查找的资源(或者它的一个依赖项)可能已被移除,或其名称已更改,或暂时不可用。谁来帮帮我!!!
’我试了很多方法,但问题没有解决

4nkexdtk

4nkexdtk1#

要解决此问题,您必须安装URL重写模块。成功安装后,您需要在React应用程序站点下创建以下规则,这些规则将重写所有非API请求到根URL(“/”),React应用程序的路由将在此处理它们。

<rule name="React Routes" stopProcessing="true">
    <match url=".*" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="true">
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        <add input="{REQUEST_URI}" pattern="^/api/(.*)" negate="true" />
    </conditions>
    <action type="Rewrite" url="/" />
</rule>

参考链接:https://dev.to/sumitkharche/how-to-deploy-react-application-on-iis-server-1ied

相关问题