React 使用客户端路由,但 IIS(或任何服务器)处理服务器端路由。确保您将服务器配置为为所有路由提供index.html。如果您使用的是 IIS,您可以通过更新 web.config 文件来完成此操作:
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="React Routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>