IIS Push State Thinks All My React Routes Are Static Files

- 1 answer

Im trying to set up my IIS to support push state by following these two posts. Configure IIS server to work with Aurelia framework and push state

However every time I try to visit a route like localhost/app/myroute IIS thinks myroute is a static file and IIS returns a 404 with

Module  IIS Web Core
Notification    MapRequestHandler
Handler StaticFile

I found in my sites Handler Mappings theres a Static File Handler with a rule of * which I guess is handling my request because it has no extension. I tried removing the rule and tried editing the rule to *.* to force an extension but neither seemed to work. Here is my current web config rewrite rules

<rule name="Main Rule" 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="api.*" negate="true" />
       <action type="Rewrite" url="/app/" />


I solved this using a combination of useBaseName in react router and <base target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" href="/app"> in my index.html file.

Seemed what was happening was all the static resources in my index.html were the issue without <base href> set which was causing the rule to trigger and not give me the correct resource back.