title: ASP.NET Core Middleware MVC/React MapSpaFallbackRoute
body: <p>I try to setup a .NET Core WebApplication that uses SPA to serve the React part of the application and MVC for my Admin-area.</p>
  
  <p>The React app is available at "/"
  The MVC part should be available at "/admin"</p>
  
  <p>I have setup my middleware as follows:</p>
  
  <pre><code>// Standard routing
          app.UseHttpsRedirection();
          app.UseStaticFiles();
          app.UseSpaStaticFiles();
  
          app.UseMvc(routes =&gt;
          {
              routes.MapRoute(
                  name: "default",
                  template: "admin/{controller=Home}/{action=Index}/{id?}");
          });
  
          // Fallback Route for /admin and /api
          app.MapWhen(x =&gt; x.Request.Path.Value.ToLower().StartsWith("/admin") || x.Request.Path.Value.ToLower().StartsWith("/api"), builder =&gt;
          {
              builder.UseMvc(routes =&gt;
              {
                  routes.MapSpaFallbackRoute(
                      name: "spa-fallback",
                      defaults: new { controller = "Home", action = "Index" });
              });
          });
  
          // use SPA for other requests
          app.MapWhen(x =&gt; !(x.Request.Path.Value.ToLower().StartsWith("/admin") || x.Request.Path.Value.ToLower().StartsWith("/api")), builder =&gt;
          {
              builder.UseSpa(spa =&gt;
              {
                  spa.Options.SourcePath = "ClientApp";
  
                  if (env.IsDevelopment())
                  {
                      spa.UseReactDevelopmentServer(npmScript: "start");
                  }
              });
          });
  </code></pre>
  
  <p>This works as intended in development mode on my machine (using the ReactDevelopmentServer).</p>
  
  <p>When I make a release and publish it, all requests are routed to the React (SPA) application, thus making my /admin MVC part inaccessible.</p>
  
  <p>What is wrong with my setup? I would appreciate any hint.</p>
  
  <p>Thanks!</p>