【发布时间】:2020-07-06 09:44:48
【问题描述】:
我正在使用以 gatsby 作为前端的 dotnet core react 模板。我有一个 aspnet 核心的路由问题。如果找不到文件,aspnet 从根目录提供 index.html。在大多数情况下这会很好,但 gatsby 会生成多个索引文件 - 每个“页面”一个:
wwwroot:
- index.html
- 第二页/
- index.html
- 第三页/
- index.html
当用户登陆根 (/) 并在客户端导航时,这可以正常工作。在页面/文件夹(例如 website.com/second-page/)内刷新时,aspnet 从根目录返回 index.html。
所以,我想要对应文件夹的索引文件。
这可以通过一些配置实现还是我必须编写自定义中间件?
这是我在 Startup.cs 中的配置方法:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
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.UseProxyToSpaDevelopmentServer("http://localhost:8000/");
}
});
}
【问题讨论】:
标签: c# asp.net .net asp.net-core gatsby