I am developing a project that involves multiple Single Page Applications that are hosted on a single .Net Core 1.0 web app.
The goal is to partition each SPA so that they all exist separately, each with their own View and Controller.
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.
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.
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.
Assuming the SPAs are named 'Dash1', 'Dash2', etc. The following fallback route works perfectly for Dash1:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
routes.MapSpaFallbackRoute("spa-fallback", new { controller = "Dash1", action = "Index" });
});
I've tried this:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
app.Map("/Dash1", HandleDash1);
}
private static void HandleDash1(IApplicationBuilder app)
{
app.UseMvc(routes =>
{
routes.MapSpaFallbackRoute("spa-fallback", new { controller = "Dash1", action = "Index" });
});
}
}
...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.
routes.MapSpaFallbackRoute("{controller}/spa-fallback", new { action = "Index" });
in your first approach?