2017-07-18 145 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>