Reputation: 33
I have an Angular2 app (RC1) that is bootstrapped from index.html. I want to setup an ASP.NET Core (RC2) route that sends all route requests with the pattern localhost/fs/* to the index.html file in wwwroot. Any thoughts?
I know I can do this with a MVC HomeController and Index view. But, I was hoping to not need a view controller. I am using MVC for API controllers.
Upvotes: 1
Views: 779
Reputation: 16795
Best solution to serve static file - use UseStaticFiles
in Startup.cs
.
As soon as you need to "redirect" several incoming urls into one static file - I think best decision is to write custom middleware which will check incoming requests and rewrite Path
when required. Then place this middleware before UseStaticFiles
in Startup.Configure
. This will work without MVC.
Of course this custom middleware may redirect user to /index.html
file (send 301 / 302 http status code with Location
http-header), and user will make another request for index file, but I don't think you need this behavior.
Upvotes: 0