为什么 blazor HeadOutlet 在 App 之后渲染
Why is blazor HeadOutlet rendering after the App
我在服务器端使用 HeadOutlet pre-rendered net6.0 应用程序来设置一些 header 标签,例如元描述,但服务器首先呈现应用程序,然后呈现 headers 让搜索引擎忽略它。
@page "/"
@namespace Example.Pages
@using Microsoft.AspNetCore.Components.Web
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@{
Layout = null;
}
<!DOCTYPE html>
<html lang="en">
<head>
<component type="typeof(HeadOutlet)" render-mode="ServerPrerendered" />
<base href="~/" />
<link href="css/site.css" rel="stylesheet" />
<link rel="preconnect" href="https://fonts.gstatic.com">
</head>
<body>
<component type="typeof(App)" render-mode="ServerPrerendered" />
<div id="blazor-error-ui">
<environment include="Staging,Production">
An error has occurred. This application may no longer respond until reloaded.
</environment>
<environment include="Development">
An unhandled exception has occurred. See browser dev tools for details.
</environment>
<a href="/" class="reload">Reload</a>
<a href="#" class="dismiss"></a>
</div>
<script src="_framework/blazor.server.js"></script>
<script src="~/outsideHandleContainerJsInterop.js"></script>
</body>
</html>
@page "/test"
<HeadContent>
<meta name="description" content="Hello World">
</HeadContent>
在浏览器中查看页面将按预期在头部呈现元标记,但在 insomnia/postman returns 初始 headers 和 blazor pre-render 标签评论
<!--Blazor:{"sequence":0,"type":"server","prerenderId":"b0376004567c4aaf9c07defc4341e21e","descriptor":"<long string here>"}--><!--Blazor:{"prerenderId":"b0376004567c4aaf9c07defc4341e21e"}-->
这是一个错误还是我遗漏了什么?我需要在页面的其余部分之前或与页面的其余部分一起呈现头部,以便搜索引擎可以选择它。
通过将 html/head/body 从 _Host.cshtml 移动到 _Layout.html 解决了这个问题。此 post 中描述的更多信息:https://github.com/dotnet/aspnetcore/issues/37293
我在服务器端使用 HeadOutlet pre-rendered net6.0 应用程序来设置一些 header 标签,例如元描述,但服务器首先呈现应用程序,然后呈现 headers 让搜索引擎忽略它。
@page "/"
@namespace Example.Pages
@using Microsoft.AspNetCore.Components.Web
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@{
Layout = null;
}
<!DOCTYPE html>
<html lang="en">
<head>
<component type="typeof(HeadOutlet)" render-mode="ServerPrerendered" />
<base href="~/" />
<link href="css/site.css" rel="stylesheet" />
<link rel="preconnect" href="https://fonts.gstatic.com">
</head>
<body>
<component type="typeof(App)" render-mode="ServerPrerendered" />
<div id="blazor-error-ui">
<environment include="Staging,Production">
An error has occurred. This application may no longer respond until reloaded.
</environment>
<environment include="Development">
An unhandled exception has occurred. See browser dev tools for details.
</environment>
<a href="/" class="reload">Reload</a>
<a href="#" class="dismiss"></a>
</div>
<script src="_framework/blazor.server.js"></script>
<script src="~/outsideHandleContainerJsInterop.js"></script>
</body>
</html>
@page "/test"
<HeadContent>
<meta name="description" content="Hello World">
</HeadContent>
在浏览器中查看页面将按预期在头部呈现元标记,但在 insomnia/postman returns 初始 headers 和 blazor pre-render 标签评论
<!--Blazor:{"sequence":0,"type":"server","prerenderId":"b0376004567c4aaf9c07defc4341e21e","descriptor":"<long string here>"}--><!--Blazor:{"prerenderId":"b0376004567c4aaf9c07defc4341e21e"}-->
这是一个错误还是我遗漏了什么?我需要在页面的其余部分之前或与页面的其余部分一起呈现头部,以便搜索引擎可以选择它。
通过将 html/head/body 从 _Host.cshtml 移动到 _Layout.html 解决了这个问题。此 post 中描述的更多信息:https://github.com/dotnet/aspnetcore/issues/37293