可以通过使用在启动Blazor WebAssembly应用程序时在WebAssemblyHostBuilder中的UseWebRoot方法来解决此问题,示例如下:
public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add("app");
//设置 pathbase
builder.Services.AddSingleton(new HttpClient
{
BaseAddress = new Uri(builder.HostEnvironment.BaseAddress + "myapp/")
});
builder.RootComponents.Add("app");
//使用UseWebRoot方法
builder.UseWebRoot("myapp");
await builder.Build().RunAsync();
}