Why need MVC for route fallback to index.html? #548

Closed
opened 2025-08-09 17:16:43 +00:00 by fergalmoran · 0 comments
Owner

Originally created by @DibranMulder on 7/26/2017

I like to use ASP.net core because of its performance. In combination with AngularJS, because of existing legacy code purposes, its nice to serve static files at a rapid pace. Spinning up MVC doesn't add to that performance. When I use html5mode in AngularJS URLs are no longer distinguishable of AngularJS- or ASP.net core routings.

If the routing is being handled in ASP.net core, this happens for instance when an user refreshes the browser, I want it to return the index.html page, causing AngularJS to handle the routing. But it might also be that the static file such as an assets, css file or JS library is requested it then should always return the static file if its present.

Now I can achieve this by adding the MapSpaFallbackRoute and creating an FallbackController with an Index action that returns the index.html page. Look at this:

app.UseMvc(routes =>
{
    routes.MapSpaFallbackRoute(
    name: "spa-fallback",
    defaults: new { controller = "Fallback", action = "Index" });
});

But this feel like a dirty hack. Isn't there a way to add a catch to the static files module to serve just the index.html when the requested routing could not be converted to a static file? If its not possible consider this issue as a feature request :)

*Originally created by @DibranMulder on 7/26/2017* I like to use ASP.net core because of its performance. In combination with AngularJS, because of existing legacy code purposes, its nice to serve static files at a rapid pace. Spinning up MVC doesn't add to that performance. When I use html5mode in AngularJS URLs are no longer distinguishable of AngularJS- or ASP.net core routings. If the routing is being handled in ASP.net core, this happens for instance when an user refreshes the browser, I want it to return the index.html page, causing AngularJS to handle the routing. But it might also be that the static file such as an assets, css file or JS library is requested it then should always return the static file if its present. Now I can achieve this by adding the MapSpaFallbackRoute and creating an FallbackController with an Index action that returns the index.html page. Look at this: ``` app.UseMvc(routes => { routes.MapSpaFallbackRoute( name: "spa-fallback", defaults: new { controller = "Fallback", action = "Index" }); }); ``` But this feel like a dirty hack. Isn't there a way to add a catch to the static files module to serve just the index.html when the requested routing could not be converted to a static file? If its not possible consider this issue as a feature request :)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/JavaScriptServices#548
No description provided.