【发布时间】:2020-02-12 13:21:02
【问题描述】:
我配置了以下 asp.net core spa 应用程序(react-redux 模板)
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UsePathBase(new PathString("/foo"));
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
}
app.UseStaticFiles();
app.UseSpaStaticFiles();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller}/{action=Index}/{id?}");
});
app.UseSpa(spa =>
{
spa.Options.SourcePath = "ClientApp";
if (env.IsDevelopment())
{
spa.UseReactDevelopmentServer(npmScript: "start");
}
});
}
我想为应用程序设置 pathBase,但 app.UsePathBase(new PathString("/foo")) 被忽略了。在 2.2 上它完美地工作。自动修改 index.html 并将所有静态文件移至相对路径。但是在 3.0 (3.1) 上,静态 + 生成的文件放在根目录下。
Generated files on .Net Core 2.2
Generated files on .Net Core 3.0
有没有人有解决这个问题的想法?或者可能是一些带有工作 pathBase 的 Startup.cs 示例?
【问题讨论】:
-
能否请您与我们分享一个可复制的演示?
-
是的,当然! Here my project。我尝试了一些描述here的方法。但仍然没有解决办法。我找不到任何修改 index.html 的代码和任何 webpack 配置来确定它如何生成静态文件。
标签: asp.net-core routing single-page-application