如何禁用 Blazor 服务器端预渲染?
How to disable Blazor server side pre-render?
要在 asp.net 核心预览版 3 上禁用服务器端预渲染,您只需评论 @(await Html.RenderComponentAsync<MyApp>())
。
自 asp.net 核心预览版 4 起,当您评论此行时,页面不会呈现,并且在主要组件 @page "/"
上,标签 <app>
保持空白。
那么,我们如何禁用服务器端预渲染?
终于在 github 中找到了核心系统的解决方案
资料来源:https://github.com/aspnet/AspNetCore/issues/9584#issuecomment-485257261
app.UseEndpoints(endpoints =>
{
endpoints.MapBlazorHub().AddComponent<App>(selector: "app");
endpoints.MapFallbackToFile("index.html"); // or - endpoints.MapFallbackToPage("/_Host");
});
希望这能奏效...
要禁用预呈现,请打开 Pages/_Host.cshtml
文件并将 Component Tag Helper 的 render-mode
属性更改为 Server:
CSHTML
<component type="typeof(App)" render-mode="Server" />
内容预呈现在 Pages/_Layout.cshtml 中被禁用:
CSHTML
<component type="typeof(HeadOutlet)" render-mode="Server" />
要在 asp.net 核心预览版 3 上禁用服务器端预渲染,您只需评论 @(await Html.RenderComponentAsync<MyApp>())
。
自 asp.net 核心预览版 4 起,当您评论此行时,页面不会呈现,并且在主要组件 @page "/"
上,标签 <app>
保持空白。
那么,我们如何禁用服务器端预渲染?
终于在 github 中找到了核心系统的解决方案 资料来源:https://github.com/aspnet/AspNetCore/issues/9584#issuecomment-485257261
app.UseEndpoints(endpoints =>
{
endpoints.MapBlazorHub().AddComponent<App>(selector: "app");
endpoints.MapFallbackToFile("index.html"); // or - endpoints.MapFallbackToPage("/_Host");
});
希望这能奏效...
要禁用预呈现,请打开 Pages/_Host.cshtml
文件并将 Component Tag Helper 的 render-mode
属性更改为 Server:
CSHTML
<component type="typeof(App)" render-mode="Server" />
内容预呈现在 Pages/_Layout.cshtml 中被禁用: CSHTML
<component type="typeof(HeadOutlet)" render-mode="Server" />