【发布时间】:2018-10-08 09:22:23
【问题描述】:
我已经使用 Visual Studio 2017 构建了一个 Angular-CLI .Net Core SPA
dotnet new angular -o my-new-app
我正在努力寻找的是在写入时如何默认调用位于ClientApp/src 文件夹内的index.html,例如
http://localhost:57782
startup.cs文件内容如下:
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.SpaServices.AngularCli;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace angular_cli
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
//services.AddMvc();
// In production, the Angular files will be served from this directory
services.AddSpaStaticFiles(configuration =>
{
configuration.RootPath = "ClientApp/dist";
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();
app.UseSpaStaticFiles();
//app.UseMvc(routes =>
//{
// routes.MapRoute(
// name: "default",
// template: "{controller}/{action=Index}/{id?}");
//});
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
spa.Options.SourcePath = "ClientApp";
if (env.IsDevelopment())
{
spa.UseAngularCliServer(npmScript: "start");
}
});
}
}
}
我故意禁用了 MVC 中间件,一切正常。但是,我有no idea by which mechanism and settings index.html is called...请问有什么好的解释吗?
【问题讨论】:
-
我希望它是
configuration.RootPath = "ClientApp/dist";和 webpack 的组合。
标签: asp.net asp.net-mvc asp.net-core angular-cli