子目录名称需要出现在四个位置。
在您的WebAPI项目的Startup.cs中,您需要:
app.UseBlazorFrameworkFiles(new PathString("/app"));
并在端点配置中:
endpoints.MapFallbackToFile("/app/{*path:nonfile}", "app/index.html");
在Wasm应用程序的wwwroot/index.html文件中:
<base href="/app/" />
在Wasm应用程序的CSProj文件中:
<StaticWebAssetBasePath>app</StaticWebAssetBasePath>
文档:https://learn.microsoft.com/zh-cn/aspnet/core/blazor/host-and-deploy/webassembly?view=aspnetcore-5.0#hosted-deployment-with-multiple-blazor-webassembly-apps
这里有一个示例实现:https://github.com/javiercn/BlazorMultipleApps
如果您使用了默认的带有 Identity 的 Wasm 模板,则会发现客户端无法正确加载,因为打包在 microsoft.aspnetcore.components.webassembly.authentication 内的静态资源未被提供。为了解决此问题,请将 index.html 中的 src 更改为绝对路径:
<script src="/_content/Microsoft.AspNetCore.Components.WebAssembly.Authentication/AuthenticationService.js"></script>
为使Identity功能正常运行,需要进行其他更改:
- 在AppSettings中,将IdentityServer客户端配置文件从"IdentityServerSPA"更改为"SPA"
- 指定"RedirectUri"和"LogoutUri"以包含新的子目录
"Clients": {
"BlazorApp.Client": {
"Profile": "SPA",
"RedirectUri": "https://localhost:44357/app/authentication/login-callback",
"LogoutUri": "https://localhost:44357/app/authentication/logout-callback"
}
}
<base href="/app/">
吗?https://learn.microsoft.com/en-us/aspnet/core/blazor/host-and-deploy/?view=aspnetcore-3.1&tabs=visual-studio#app-base-path - Brian ParkerClient/wwwroot/app/index.html
中添加了<base href="/app/" />',其中包含
<div id="app">...并加载
blazor.webassembly.js`文件。 - Coupz