要求
.net core 2.1
引用包
Microsoft.AspNetCore.SpaServices
先在angular目录下执行
npm i
npm run build
关键代码
services.AddSpaStaticFiles(c =>
{
//这里设置路由
c.RootPath = "ClientApp/dist";
});
app.UseSpa(spa =>
{
// To learn more about options for serving an Angular SPA from ASP.NET Core,
// see https://go.microsoft.com/fwlink/?linkid=864501
//这里是angular项目的根目录
spa.Options.SourcePath = "ClientApp";
if (env.IsDevelopment())
{
spa.UseAngularCliServer(npmScript: "start");
}
});
示例代码
参考资料
通过 ASP.NET Core 使用 Angular 项目模板
Implement ASP.NET Core SPA template features in an Angular 6 app