[英]Enable angular routes with asp.net core
i'm trying to build a web app with asp.net core
for back-end side and angular 1.5.x
for front-end side. 我正在尝试构建一个Web应用程序,后端侧为asp.net core
,前端侧为angular 1.5.x
the problem is haw to enable angular routes to be analyzed by the server. 问题是如何使服务器能够分析角度路线。 i added these lines of code to the startup.cs
and evry thing works fine: 我将这些代码行添加到了startup.cs
并且evry的工作正常:
DefaultFilesOptions options = new DefaultFilesOptions();
options.DefaultFileNames.Clear();
options.DefaultFileNames.Add("Index.html");
app.Use(async (context, next) =>
{
await next();
if (context.Response.StatusCode == 404 && !Path.HasExtension(context.Request.Path.Value))
{
context.Request.Path = "/Index.html";
await next();
}
})
.UseCors("AllowAll")
.UseDefaultFiles(options)
.UseStaticFiles()
.UseIdentity()
.UseMvc();
but i looks like it's not a good practice, and this problem should be solved in the appsettings.json
. 但是我看起来这不是一个好习惯,这个问题应该在appsettings.json
解决。 any ideas ? 有任何想法吗 ?
The answer (mostly) is in the UseMVC options... you should implement server-side routes as shown 答案(大部分)在UseMVC选项中……您应该实现服务器端路由,如下所示
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
routes.MapSpaFallbackRoute("spa-fallback", new { controller = "Home", action = "Index" });
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.