【问题标题】:How to redirect all routes to index page in web config on azure?如何将所有路由重定向到 azure 上 Web 配置中的索引页面?
【发布时间】: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


    【解决方案1】:

    您应该能够将您的管理员匹配规则换成&lt;match url=".*" /&gt;,就在您的开始&lt;conditions&gt; 标记上方。更多信息请查看this blog post

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-09
      • 2023-03-15
      • 2021-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-07
      • 2017-08-30
      相关资源
      最近更新 更多