默认情况下,SPA 在站点根目录上启用。但是,我想将其移至特定路径,例如:http://localhost:port/frontend
//public void ConfigureServices(IServiceCollection services)
services.AddSpaStaticFiles(configuration =>
{
configuration.RootPath = "ClientApp/dist/myApp";
});
//public void Configure(IApplicationBuilder app)
app.Map("/frontend", frontendApp =>
{
frontendApp.UseSpaStaticFiles(new StaticFileOptions
{
RequestPath = "/frontend'
});
frontendApp.UseSpa(spa =>
{
spa.Options.SourcePath = "/ClientApp";
if (Configuration.GetValue<bool>("UseAngularCliServer"))
{
spa.UseProxyToSpaDevelopmentServer("http://localhost:4200/");
}
});
});
当我在 /frontend 文件夹中运行 npm build 时,这将起作用,但是我在配置 UseProxyToSpaDevelopmentServer 时遇到了麻烦。它显示 index.html,但引用
http://localhost:port/vendor.js
代替http://localhost:port/frontend/vendor.js
当我使用ng serve --base-href=/vnext/
对 localhost:port/frontend/vendor.js 的请求返回 index.html 的内容。