Is there a way to make a catch all route serve a static file?
Looking at this http://blog.nbellocam.me/2016/03/21/routing-angular-2-asp-net-core/
I basically
ASP.NET Core catch all routes for Web API and MVC are configured differently
With Web API (if you're using prefix "api" for all server-side controllers eg. Route("api/[controller"]
):
app.Use(async (context, next) =>
{
await next();
var path = context.Request.Path.Value;
if (!path.StartsWith("/api") && !Path.HasExtension(path))
{
context.Request.Path = "/index.html";
await next();
}
});
app.UseStaticFiles();
app.UseDefaultFiles();
app.UseMvc();
With MVC (dotnet add package Microsoft.AspNetCore.SpaServices -Version x.y.z
):
app.UseStaticFiles();
app.UseDefaultFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}");
routes.MapSpaFallbackRoute("spa", new { controller = "Home", action = "Index" });
});