简体   繁体   English

Blazor 预渲染显示布局

[英]Blazor prerendering show layout

I'm trying to implement blazor prerendering.我正在尝试实现 blazor 预渲染。 It seems to work fine, but when I refresh the page, the layout (The container of the actual routed page) is not visible.它似乎工作正常,但是当我刷新页面时,布局(实际路由页面的容器)不可见。 I followed the instructions here https://jonhilton.net/blazor-wasm-prerendering/ and created a _Host.cshtml file in the Server project.我按照https://jonhilton.net/blazor-wasm-prerendering/此处的说明在服务器项目中创建了一个 _Host.cshtml 文件。 But the Client/App.razor which is looking as follows is not included:但不包括如下所示的 Client/App.razor:

<Fluxor.Blazor.Web.StoreInitializer />

<Router AppAssembly="@typeof(App).Assembly">
    <Found Context="routeData">
        <AppRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
        <FocusOnNavigate RouteData="@routeData" Selector="h1" />
    </Found>
    <NotFound>
        <PageTitle>@Frontend.ErrotPage_NotFoundTitle</PageTitle>
        <LayoutView Layout="@typeof(MainLayout)">
            <MudAlert Severity="Severity.Error" Variant="Variant.Filled" Square="true" Class="ma-2">@Frontend.ErrorPage_NotFound</MudAlert>
        </LayoutView>
    </NotFound>
</Router>

Do I have to move this file to the Server project, or what is the right way to accomplish this?我是否必须将此文件移动到服务器项目,或者完成此操作的正确方法是什么?

Seems like the layout was rendered already.似乎布局已经呈现。 But the parts of it were not rendered since it was depending on the current user which was not available on the server side.但是它的某些部分没有被渲染,因为它取决于当前用户,而当前用户在服务器端不可用。 The solution will be to provide the current user also on server side (Which is not yet possible with Blazor 6).解决方案是在服务器端也提供当前用户(Blazor 6 尚无法实现)。

Here is a GitHub repository for .NET 6 version written by danroth27 是 danroth27 编写的 .NET 6 版本的 GitHub 存储库

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM