问题
I am creating a single page app in the new ASP 5. How can I tell it to always server Home/Index no matter what (unless the request has wwwroot in the path)?
More specifically, I would like something like this:
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "Home/Index/");
});
where first it searches the static files and then it if none are found, it just serves up Home/Index
回答1:
How about a catch-all route?
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{*url}",
defaults: new { controller = "Home", action = "Index" });
});
来源:https://stackoverflow.com/questions/35926027/invoke-same-action-for-all-urls-in-asp-net-core-mvc