2017-07-18 160 views
0

我想让我的路线与IIS和React路由器v4使用BrowserRouter。IIS规则与反应路由器v4

在我的本地主机上,我有我所有的路线按预期工作。反应路由器处理一切就像我希望它:

现在,在IIS我已经设置了忽略规则“/ appfolder/API/*'用于为我的应用程序提供API。这样可行。

如何让IIS重定向到'http://www.example.com/appfolder/dest/CODE'并让React Router根据其规则处理它。如果我重定向到'/appfolder/index.html',我就放弃我想保留给ReactRouter处理的'CODE'。

如果我尝试使用正则表达式捕获组重定向到'http://www.example.com/appfolder/dest/CODE',我会得到'ERR_TOO_MANY_REDIRECTS'。

我目前在我的web.config这条规则:

<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="^/appfolder/api/" negate="true" /> 
     </conditions> 
     <action type="Redirect" url="/appfolder/dest/CODE" /> 
     <!-- also tried this --> 
     <!-- action type="Redirect" url="/appfolder/index.html" /--> 
    </rule> 

回答

0

我找到了解决办法。我将我的动作类型改为Rewrite,它的功能就像一个魅力。

IIS规则最终解决方案:

<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="^/appfolder/api/" negate="true" /> 
    </conditions> 
    <action type="Rewrite" url="/appfolder/index.html" /> 
</rule>