
Title
Used to set page title
BasicUsage
Add the Title
component to the web page and set the text
attribute
Demo
<b>Set the <code>Text</code> property</b>
@page "/titles"
<Title Text="I am the title" />
<p>Test page<p/>
Advanced usage
There is no need to add the Title
component to the webpage, and the injection service TitleService
is called
Demo
Pay attention:
When using this method, please add not set
Text
attribute in App
or MainLayout
or Page
The Title
component of [Inject]
[NotNull]
private TitleService? TitleService { get; set; }
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);
await TitleService.SetTitle("I am the title");
}
Static method
Call the TitleService
static method directly
Demo
Pay attention
When using this method, please add not set
Text
attribute in App
or MainLayout
or Page
The Title
component of protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);
await TitleService.SetWebSiteTitle("I am the title");
}
@page "/titles"
@inject IStringLocalizer<Titles> Localizer
<h3>Title</h3>
<h4>Used to set page title</h4>
<Tips>
@((MarkupString) Localizer["Tips"].Value)
</Tips>
<DemoBlock Title="BasicUsage" Introduction="Add the <code>Title</code> component to the web page and set the <code>text</code> attribute" Name="Normal">
<Tips>
<p>
The <code>Title</code> component is used by ordinary components after setting <code>text</code>, and can be called by the service when the <code>text</code> attribute is not set
</p>
</Tips>
<p><b>Set the <code>Text</code> property</b></p>
<Pre>
@page "/titles"
<Title Text="I am the title" />
<p>Test page<p/>
</Pre>
</DemoBlock>
<DemoBlock Title="Advanced usage" Introduction="There is no need to add the <code>Title</code> component to the webpage, and the injection service <code>TitleService</code> is called" Name="Advance">
<p>
<b>Pay attention:</b>
<div>When using this method, please add <b>not set <code>Text</code> attribute in <code>App</code> or <code>MainLayout</code> or <code>Page</code> The <code>Title</code> component of </b></div>
</p>
<Pre>[Inject]
[NotNull]
private TitleService? TitleService { get; set; }
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);
await TitleService.SetTitle("I am the title");
}
</Pre>
</DemoBlock>
<DemoBlock Title="Static method" Introduction="Call the <code>TitleService</code> static method directly" Name="Static">
<p>
<b>Pay attention</b>
<div>@((MarkupString) Localizer["StaticDiv"].Value)</div>
</p>
<Pre>protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);
await TitleService.SetWebSiteTitle("I am the title");
}
</Pre>
</DemoBlock>
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Website: https://www.blazor.zone or https://argozhang.github.io/
namespace BootstrapBlazor.Shared.Samples;
/// <summary>
/// Title 网站标题示例代码
/// </summary>
public partial class Title
{
}