title: .Net Core MVC Routing: Setting MapSpaFallbackRoute Conditionally Per Controller
body: <p>I am developing a project that involves multiple Single Page Applications that are hosted on a single .Net Core 1.0 web app.</p>
  
  <p>The goal is to partition each SPA so that they all exist separately, each with their own View and Controller.</p>
  
  <p>In Startup.cs, am using Microsoft.AspNetCore.SpaServices MapSpaFallbackRoute to pass off the deep links to the SPAs (in this case Angular 2), so MVC doesn't get confused and throw a 404 on page refresh.</p>
  
  <p>I have it working for one SPA at a time when I set the Controller manually in MapSpaFallbackRoute, but I can't figure out a way set it conditionally for each SPA Controller.</p>
  
  <p>I'm assuming that a combination of Mapwhen() and Run() will get me where I need to be, but I can't seem to get the syntax correct. </p>
  
  <p>Assuming the SPAs are named 'Dash1', 'Dash2', etc. The following fallback route works perfectly for Dash1:</p>
  
  <pre><code> app.UseMvc(routes =&gt;
          {
              routes.MapRoute(
                  name: "default",
                  template: "{controller=Home}/{action=Index}/{id?}");
  
              routes.MapSpaFallbackRoute("spa-fallback", new { controller = "Dash1", action = "Index" });
          });
  </code></pre>
  
  <p>I've tried this:</p>
  
  <pre><code>public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
      {
  
          app.UseMvc(routes =&gt;
          {
              routes.MapRoute(
                  name: "default",
                  template: "{controller=Home}/{action=Index}/{id?}");
          });
          app.Map("/Dash1", HandleDash1);
  
      }
  
      private static void HandleDash1(IApplicationBuilder app)
      {
          app.UseMvc(routes =&gt;
          {
              routes.MapSpaFallbackRoute("spa-fallback", new { controller = "Dash1", action = "Index" });
          });
      }
  }
  </code></pre>
  
  <p>...But then when I navigate to Dash1 and try to refresh the page, the browser prepends '/Dash1/' to all of the http requests and breaks everything.</p>