Skip to content

Commit 2af48bc

Browse files
authored
HeadOutlet component 8.0 updates (#29793)
1 parent 9c92929 commit 2af48bc

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

aspnetcore/blazor/components/control-head-content.md

+27-7
Original file line numberDiff line numberDiff line change
@@ -64,33 +64,53 @@ In a **required**, shared `_Layout.cshtml` file of a prerendered hosted Blazor W
6464

6565
The <xref:Microsoft.AspNetCore.Components.Web.HeadOutlet> component renders content provided by <xref:Microsoft.AspNetCore.Components.Web.PageTitle> and <xref:Microsoft.AspNetCore.Components.Web.HeadContent> components.
6666

67-
In an app created from the Blazor WebAssembly project template, the <xref:Microsoft.AspNetCore.Components.Web.HeadOutlet> component is added to the <xref:Microsoft.AspNetCore.Components.WebAssembly.Hosting.WebAssemblyHostBuilder.RootComponents> collection of the <xref:Microsoft.AspNetCore.Components.WebAssembly.Hosting.WebAssemblyHostBuilder> in `Program.cs`:
67+
:::moniker range=">= aspnetcore-8.0"
6868

69-
```csharp
70-
builder.RootComponents.Add<HeadOutlet>("head::after");
69+
In a Blazor Web App created from the project template, the <xref:Microsoft.AspNetCore.Components.Web.HeadOutlet> component in `App.razor` renders `<head>` content:
70+
71+
```razor
72+
<head>
73+
...
74+
<HeadOutlet />
75+
</head>
7176
```
7277

73-
When the [`::after` pseudo-selector](https://developer.mozilla.org/docs/Web/CSS/::after) is specified, the contents of the root component are appended to the existing head contents instead of replacing the content. This allows the app to retain static head content in `wwwroot/index.html` without having to repeat the content in the app's Razor components.
78+
:::moniker-end
7479

75-
:::moniker range=">= aspnetcore-7.0"
80+
:::moniker range=">= aspnetcore-7.0 < aspnetcore-8.0"
7681

7782
In Blazor Server apps created from the Blazor Server project template, a [Component Tag Helper](xref:mvc/views/tag-helpers/builtin-th/component-tag-helper) renders `<head>` content for the <xref:Microsoft.AspNetCore.Components.Web.HeadOutlet> component in `Pages/_Host.cshtml`:
7883

84+
```cshtml
85+
<head>
86+
...
87+
<component type="typeof(HeadOutlet)" render-mode="ServerPrerendered" />
88+
</head>
89+
```
90+
7991
:::moniker-end
8092

8193
:::moniker range="< aspnetcore-7.0"
8294

8395
In Blazor Server apps created from the Blazor Server project template, a [Component Tag Helper](xref:mvc/views/tag-helpers/builtin-th/component-tag-helper) renders `<head>` content for the <xref:Microsoft.AspNetCore.Components.Web.HeadOutlet> component in `Pages/_Layout.cshtml`:
8496

85-
:::moniker-end
86-
8797
```cshtml
8898
<head>
8999
...
90100
<component type="typeof(HeadOutlet)" render-mode="ServerPrerendered" />
91101
</head>
92102
```
93103

104+
:::moniker-end
105+
106+
In an app created from the Blazor WebAssembly project template, the <xref:Microsoft.AspNetCore.Components.Web.HeadOutlet> component is added to the <xref:Microsoft.AspNetCore.Components.WebAssembly.Hosting.WebAssemblyHostBuilder.RootComponents> collection of the <xref:Microsoft.AspNetCore.Components.WebAssembly.Hosting.WebAssemblyHostBuilder> in `Program.cs`:
107+
108+
```csharp
109+
builder.RootComponents.Add<HeadOutlet>("head::after");
110+
```
111+
112+
When the [`::after` pseudo-selector](https://developer.mozilla.org/docs/Web/CSS/::after) is specified, the contents of the root component are appended to the existing head contents instead of replacing the content. This allows the app to retain static head content in `wwwroot/index.html` without having to repeat the content in the app's Razor components.
113+
94114
## Not found page title
95115

96116
In Blazor apps created from Blazor project templates, the `NotFound` component template in the `App` component (`App.razor`) sets the page title to `Not found`.

aspnetcore/blazor/state-management.md

+1-5
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,7 @@ To disable prerendering, open the `Pages/_Host.cshtml` file and change the `rend
270270

271271
:::moniker range=">= aspnetcore-6.0"
272272

273-
[Prerendering of `<head>` content](xref:blazor/components/control-head-content) is disabled in [`<head>` content](xref:blazor/project-structure#location-of-head-content):
274-
275-
```cshtml
276-
<component type="typeof(HeadOutlet)" render-mode="Server" />
277-
```
273+
When prerendering is disabled, [prerendering of `<head>` content](xref:blazor/components/control-head-content) is disabled.
278274

279275
:::moniker-end
280276

0 commit comments

Comments
 (0)