【发布时间】:2017-11-08 22:10:18
【问题描述】:
我正在使用部署在 azure 上的 react 应用程序。我正在使用反应路由器 Browserhistory 模块。目前,我在 azure 上的 web.config 中有以下规则:
<rule name="admin rule" stopProcessing="true">
<match url="admin" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" matchType="Pattern" pattern="api/(.*)" negate="true" />
</conditions>
<action type="Rewrite" url="/" />
</rule>
这行得通,可以在浏览器的 url 窗口中刷新和手动输入 /admin 路由。如果未应用此规则,我将无法刷新或手动输入网址。 (见问题:React-router urls don't work when refreshing or writting manually)
但我实际上希望这适用于每条路线,也适用于动态路线。例如:
- /购物车
- /product/uniqueid
- /示例
我可以编写什么规则,以便每个路由都被重写为索引,就像在管理路由中一样?
【问题讨论】:
标签: reactjs azure url-rewriting web-config react-router