Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HeadOutlet component 8.0 updates #29793

Merged
merged 1 commit into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions aspnetcore/blazor/components/control-head-content.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,33 +64,53 @@ In a **required**, shared `_Layout.cshtml` file of a prerendered hosted Blazor W

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.

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`:
:::moniker range=">= aspnetcore-8.0"

```csharp
builder.RootComponents.Add<HeadOutlet>("head::after");
In a Blazor Web App created from the project template, the <xref:Microsoft.AspNetCore.Components.Web.HeadOutlet> component in `App.razor` renders `<head>` content:

```razor
<head>
...
<HeadOutlet />
</head>
```

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.
:::moniker-end

:::moniker range=">= aspnetcore-7.0"
:::moniker range=">= aspnetcore-7.0 < aspnetcore-8.0"

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`:

```cshtml
<head>
...
<component type="typeof(HeadOutlet)" render-mode="ServerPrerendered" />
</head>
```

:::moniker-end

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

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`:

:::moniker-end

```cshtml
<head>
...
<component type="typeof(HeadOutlet)" render-mode="ServerPrerendered" />
</head>
```

:::moniker-end

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`:

```csharp
builder.RootComponents.Add<HeadOutlet>("head::after");
```

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.

## Not found page title

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`.
Expand Down
6 changes: 1 addition & 5 deletions aspnetcore/blazor/state-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,7 @@ To disable prerendering, open the `Pages/_Host.cshtml` file and change the `rend

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

[Prerendering of `<head>` content](xref:blazor/components/control-head-content) is disabled in [`<head>` content](xref:blazor/project-structure#location-of-head-content):

```cshtml
<component type="typeof(HeadOutlet)" render-mode="Server" />
```
When prerendering is disabled, [prerendering of `<head>` content](xref:blazor/components/control-head-content) is disabled.

:::moniker-end

Expand Down