来自这篇文章:https://stackoverflow.com/a/78353968/8031370
在 App.razor 中:
<base href="@BaseUrl" />
在 App.razor 底部添加:
@code {
[CascadingParameter]
private HttpContext HttpContext { get; set; } = null!;
private string BaseUrl => $"{HttpContext.Request.PathBase}/";
}