TryReact

Правило URL Rewrite для корректной работы SPA приложений на

6/24/2019 1:22:48 PM

Changes

Details

diff --git a/TryReact/TryRoute/Web.config b/TryReact/TryRoute/Web.config
index 4cd752a..b1e160d 100644
--- a/TryReact/TryRoute/Web.config
+++ b/TryReact/TryRoute/Web.config
@@ -7,7 +7,7 @@
 <configuration>
   <system.web>
     <compilation debug="true" targetFramework="4.5"/>
-    <httpRuntime targetFramework="4.5"/>
+    <httpRuntime targetFramework="4.5"/> 
   </system.web>
   <system.codedom>
     <compilers>
@@ -20,4 +20,27 @@
     </compilers>
   </system.codedom>
 
+  <!--Правило для URL Rewriter для корректной работы ссылок для SPA-->
+  <system.webServer>
+    <rewrite>
+      <rules>
+        <rule name="SPA Routes" stopProcessing="true">
+          <!-- match everything by default -->
+          <match url=".*" />
+          <conditions logicalGrouping="MatchAll">
+            <!-- unless its a file -->
+            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
+            <!-- or a directory -->
+            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
+            <!-- or is under the /api directory -->
+            <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
+            <!-- list other routes or route prefixes here if you need to handle them server side -->
+          </conditions>
+          <!-- rewrite it to /index.html -->
+          <action type="Rewrite" url="/index.html" />
+        </rule>
+      </rules>
+    </rewrite>
+  </system.webServer>
+
 </configuration>