ReactJS中嵌套URL的URL重写
我正在IIS上运行react应用程序,我使用URL重写进行路由配置,这是我的web.config文件:ReactJS中嵌套URL的URL重写,reactjs,iis,url-rewriting,Reactjs,Iis,Url Rewriting,我正在IIS上运行react应用程序,我使用URL重写进行路由配置,这是我的web.config文件: <?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="Re
<?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嵌套或子页面?当您从子文件夹提供react应用程序时,您需要在路由中设置基本名称
或
请尝试以下iis url重写规则:
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^" ignoreCase="false" />
<conditions logicalGrouping="MatchAny">
<add input="{DOCUMENT_ROOT}{URL}" matchType="IsFile" ignoreCase="false" />
<add input="{DOCUMENT_ROOT}{URL}" matchType="IsDirectory" ignoreCase="false" />
</conditions>
<action type="None" />
</rule>
<!--# Fallback all other routes to index.html-->
<rule name="Imported Rule 2" stopProcessing="true">
<match url="^" ignoreCase="false" />
<action type="Rewrite" url="/path/to/subfolder/index.html" />
</rule>
</rules>
</rewrite>
我也有同样的问题,但我无法找到任何路线去工作,你在哪里找到这个web.config?其他目录中是否有其他web.config?basename的路径是否应类似于/appfolder/app/build/?到生成文件夹?@Erik在站点文件夹中,您必须选择生成文件夹,但在URL重写规则中,您可以设置索引文件。如果索引文件位于子文件夹中,请添加子文件夹。