What I use works well Microsoft.AspNetCore.Builder.SpaRouteExtensions.MapSpaFallbackRoute :
app.UseMvc(routes => { // Default route for SPA components, excluding paths which appear to be static files (have an extension) routes.MapSpaFallbackRoute( "spaFallback", new { controller = "Home", action = "Index" }); });
HomeController.Index has the equivalent of your index.html . Perhaps you can also go to a static page.
Disable the theme, but if you also have an API in the same project in the api folder, you can set the default 404 response for any API routes that do not match:
routes.MapRoute( "apiDefault", "api/{*url}", new { controller = "Home", action = "ApiNotFound" });
As a result, you get the following behavior:
/controller => There is no extension, so open the default SPA page from HomeController.Index and let SPA handle routing/file.txt => Detected extension, serves for a static file/api/controller => correct API response (use attributive routing or configure another map for API controllers)/api/non-existent-route => 404 NotFound() returns from HomeController.ApiNotFound
In many cases, you will need the API in a separate project, but this is a viable alternative.
source share