【发布时间】:2020-08-25 10:36:05
【问题描述】:
我在 IIS 上运行 react 应用程序,我使用 URL 重写进行路由配置,这是我的 web.config 文件:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="ReactRouter Routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(docs)" negate="true" />
</conditions>
<action type="Rewrite" url="index.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
此代码适用于 localhost/ReactApp/User 等 url, 现在我希望它像 localhost/ReactApp/User/Edit 一样工作,但它不适用于显示空白页面的子页面, 此问题仅在构建和部署之后出现,请告诉我它如何适用于 /User/Edit 嵌套页面或子页面?
【问题讨论】:
-
我有同样的问题,但我无法让任何路线工作,你在哪里使用这个 web.config?其他目录中是否还有其他 web.config?
标签: reactjs iis url-rewriting