Skip to content

Commit 22bcd78

Browse files
committed
refactor: 增加 RootTemplate 细化 Root 组件使用方法
1 parent bc4ad73 commit 22bcd78

File tree

8 files changed

+65
-79
lines changed

8 files changed

+65
-79
lines changed

src/BootstrapBlazor.Server/Components/Components/InstallContent.razor

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,16 @@
11
@using Microsoft.Extensions.DependencyInjection
22
@inject PackageVersionService VersionManager
33
@inject IStringLocalizer<InstallContent> Localizer
4-
5-
<h3>@Title</h3>
6-
7-
<h4>@Localizer["Heading"]</h4>
84
@inject IOptionsMonitor<WebsiteOptions> WebsiteOption
95

10-
<p>@Localizer["P1"]</p>
11-
<ul class="ul-demo">
12-
<li><code>visual studio</code> @Localizer["P2"]</li>
13-
<li><code>net5</code> @Localizer["P3"] <code>net6</code> <code>net7</code></li>
14-
</ul>
15-
<p><code>BootstrapBlazor</code> @Localizer["P4"] <code>NET6/NET7/NET8/NET9</code></p>
16-
17-
<h4>@Localizer["P5"]</h4>
6+
<h3>@Title</h3>
187

19-
<p>@Localizer["P6"] <a href="template">[@Localizer["P7"]]</a> @Localizer["P8"]</p>
8+
<h5>@Localizer["P5"]</h5>
9+
<p>@((MarkupString)Localizer["InstallByTemplate"].Value)</p>
2010

21-
<h4>@Localizer["P9"]</h4>
11+
<h5 class="code-label">@Localizer["P9"]</h5>
2212

23-
<h5>@Localizer["P10"]</h5>
13+
<p class="code-label">@Localizer["P10"]</p>
2414
<p class="code-label">1. @Localizer["P11"]</p>
2515
<p class="code-label">2. @Localizer["P12"]</p>
2616
<p class="code-label">3. @Localizer["P13"] <b>Blazor App</b> @Localizer["P14"] <b>@Localizer["P15"]</b>, @Localizer["P16"] <b>Create</b></p>
@@ -54,7 +44,7 @@
5444
&lt;link href="BlazorApp1.styles.css" rel="stylesheet"&gt;
5545
&lt;/head&gt;</Pre>
5646

57-
<p class="code-label">4. @Localizer["P25"]</p>
47+
<p class="code-label">4. @((MarkupString)Localizer["P25"].Value)</p>
5848
@ScriptsTemplate
5949
<Pre>&lt;body&gt;
6050
...
@@ -68,25 +58,11 @@
6858
@ServicesTemplate
6959

7060
<p class="code-label">6. @Localizer["P28"]</p>
71-
<p>@Localizer["P29"] <code>~/_Imports.razor</code> @Localizer["P30"] <code>Razor</code> @Localizer["P31"]</p>
61+
<p>@Localizer["P29"] <code>_Imports.razor</code> @Localizer["P30"] <code>Razor</code> @Localizer["P31"]</p>
7262
<Pre><b>@@using BootstrapBlazor.Components</b></Pre>
7363

74-
<p class="code-label">7. @Localizer["P32"] <code>BootstrapBlazorRoot</code> @Localizer["P33"] <code>~/App.razor</code> @Localizer["P34"]</p>
75-
<Pre>&lt;BootstrapBlazorRoot&gt;
76-
&lt;Router AppAssembly="@@typeof(App).Assembly"&gt;
77-
&lt;Found Context="routeData"&gt;
78-
&lt;PageTitle&gt;Title&lt;/PageTitle&gt;
79-
&lt;RouteView RouteData="@@routeData" DefaultLayout="@@typeof(MainLayout)" /&gt;
80-
&lt;FocusOnNavigate RouteData="@@routeData" Selector="h1" /&gt;
81-
&lt;/Found&gt;
82-
&lt;NotFound&gt;
83-
&lt;PageTitle&gt;Not found&lt;/PageTitle&gt;
84-
&lt;LayoutView Layout="@@typeof(MainLayout)"&gt;
85-
&lt;p&gt; @Localizer["P35"] ...&lt;/p&gt;
86-
&lt;/LayoutView&gt;
87-
&lt;/NotFound&gt;
88-
&lt;/Router&gt;
89-
&lt;/BootstrapBlazorRoot&gt;</Pre>
64+
<p class="code-label">7. @((MarkupString)Localizer["AddRootText"].Value)</p>
65+
@RootTemplate
9066

9167
<h5>@Localizer["P36"]</h5>
9268
<p>@Localizer["P37"] <code>BootstrapBlazor</code> @Localizer["P38"]:</p>

src/BootstrapBlazor.Server/Components/Components/InstallContent.razor.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ public sealed partial class InstallContent
5151
[Parameter]
5252
public RenderFragment? ServicesTemplate { get; set; }
5353

54+
/// <summary>
55+
///
56+
/// </summary>
57+
[Parameter]
58+
public RenderFragment? RootTemplate { get; set; }
59+
5460
/// <summary>
5561
///
5662
/// </summary>

src/BootstrapBlazor.Server/Components/Pages/Install_Maui.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ return builder.Build();
7777
<p>@Localizer["P24"] <code>~/_Imports.razor</code> @Localizer["P25"] <code>Razor</code> @Localizer["P26"]</p>
7878
<Pre><b>@@using BootstrapBlazor.Components</b></Pre>
7979

80-
<p class="code-label">@Localizer["P27"] <code>BootstrapBlazorRoot</code> @Localizer["P28"] <code>~/Components/Routes.razor</code> @Localizer["P29"]</p>
80+
<p class="code-label">@((MarkupString)Localizer["AddRootText"].Value)</p>
8181
<Pre>&lt;BootstrapBlazorRoot&gt;
8282
&lt;Router AppAssembly="@@typeof(App).Assembly"&gt;
8383
&lt;Found Context="routeData"&gt;

src/BootstrapBlazor.Server/Components/Pages/Install_Server.razor

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,19 @@
99
</ChooseTemplate>
1010
<SheetTemplate>
1111
<ul class="ul-demo">
12-
<li><code>~/Pages/_Host.cshtml</code> <b>.NET5</b></li>
13-
<li><code>~/Pages/_Layout.cshtml</code> <b>.NET6/.NET7</b></li>
12+
<li><code>~/Pages/_Layout.cshtml</code> <b>NET6/NET7</b></li>
13+
<li><code>App.razor</code> <b>NET8/NET9</b></li>
1414
</ul>
1515
</SheetTemplate>
1616
<ScriptsTemplate>
1717
<ul class="ul-demo">
18-
<li><code>~/Pages/_Host.cshtml</code> <b>.NET5</b></li>
19-
<li><code>~/Pages/_Layout.cshtml</code> <b>.NET6/.NET7</b></li>
18+
<li><code>~/Pages/_Layout.cshtml</code> <b>NET6/NET7</b></li>
19+
<li><code>App.razor</code> <b>NET8/NET9</b></li>
2020
</ul>
2121
</ScriptsTemplate>
2222
<ServicesTemplate>
2323
<ul class="ul-demo">
24-
<li><code>Starup.cs</code> <b>.NET5</b></li>
25-
<li><code>Program.cs</code> <b>.NET6/.NET7</b></li>
24+
<li><code>Program.cs</code> <b>NET6/NET7/NET8/NET9</b></li>
2625
</ul>
2726
<p><b>Startup.cs</b></p>
2827
<Pre>namespace MyBlazorAppName
@@ -51,4 +50,21 @@ builder.Services.AddServerSideBlazor();
5150
var app = builder.Build();
5251
//more code may be present here</Pre>
5352
</ServicesTemplate>
53+
<RootTemplate>
54+
<ul class="ul-demo">
55+
<li><code>App.razor</code> <b>NET6/NET7</b></li>
56+
<li><code>MainLayout.razor</code> <b>NET8/NET9</b></li>
57+
</ul>
58+
59+
<Pre>// NET6/NET7
60+
&lt;BootstrapBlazorRoot&gt;
61+
&lt;Router&gt;&lt;Router&gt;
62+
&lt;/BootstrapBlazorRoot&gt;
63+
</Pre>
64+
65+
<Pre>// NET8/NET9
66+
&lt;BootstrapBlazorRoot&gt;
67+
&lt;@@Body
68+
&lt;/BootstrapBlazorRoot&gt;</Pre>
69+
</RootTemplate>
5470
</InstallContent>

src/BootstrapBlazor.Server/Components/Pages/Install_WebApp.razor

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,17 @@
2525

2626
<h5>3. 添加字体与样式</h5>
2727
<p><code>App.razor</code> 文件在 <code>head</code> 位置添加如下内容</p>
28-
<Pre class="mb-3">// FontAwesoem 字体样式 注意需要引用 BootstrapBlazor.FontAwesome 包
28+
<Pre class="mb-3">// FontAwesome 字体图标样式 注意需要引用 BootstrapBlazor.FontAwesome 包
2929
&lt;link rel="stylesheet" href="_content/BootstrapBlazor.FontAwesome/css/font-awesome.min.css" /&gt;
3030
// 组件样式已集成 Bootstrap 最新版
3131
&lt;link rel="stylesheet" href="_content/BootstrapBlazor/css/bootstrap.blazor.bundle.min.css" /&gt;
32-
// Motronic 样式可不添加
32+
// Motronic 主题可选建议添加
3333
&lt;link rel="stylesheet" href="_content/BootstrapBlazor/css/motronic.min.css" /&gt;</Pre>
3434

35-
<h5>4. 添加脚本</h5>
35+
<h5>4. 添加脚本 (<code>9.7.1</code> 版本后可跳过此步骤)</h5>
3636
<p><code>App.razor</code> 文件在 <code>body</code> 结尾位置添加如下内容它应与默认 blazor 脚本位于同一位置。</p>
3737
<Pre class="mb-3">// 添加 BootstrapBlazor 脚本
38-
&lt;script src="_content/BootstrapBlazor/js/bootstrap.blazor.bundle.min.js"&gt;&lt;/script&gt;
39-
&lt;script src="_framework/blazor.web.js"&gt;&lt;/script&gt;</Pre>
38+
&lt;script src="_content/BootstrapBlazor/js/bootstrap.blazor.bundle.min.js"&gt;&lt;/script&gt;</Pre>
4039

4140
<h5>5. 删除引用</h5>
4241
<p><code>App.razor</code> 文件,从项目中删除 bootstrap 样式,请同时删除 bootstrap 和 open-iconic 文件夹</p>
@@ -46,7 +45,7 @@
4645
<Pre class="mb-3">// 增加 BootstrapBlazor 服务
4746
builder.Services.AddBootstrapBlazor();</Pre>
4847

49-
<h5>7. 添加组件</h5>
48+
<h5>7. 添加 <code>BootstrapBlazorRoot</code> 组件</h5>
5049
<p>根据项目情况增加 <code>BootstrapBlazorRoot</code> 组件,如 <code>MainLayout</code> 文件中,使用 <code>BootstrapBlazorRoot</code> 将原有内容包裹即可</p>
5150
<Pre class="mb-3">&lt;BootstrapBlazorRoot&gt;
5251
&lt;Header&gt;&lt;/Header&gt;

src/BootstrapBlazor.Server/Components/Pages/Install_wasm.razor

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,15 @@ static async Task SetCultureAsync(WebAssemblyHost host)
4444
}
4545
</Pre>
4646
</ServicesTemplate>
47+
<RootTemplate>
48+
<ul class="ul-demo">
49+
<li><code>App.razor</code> <b>NET6/NET7/NET8/NET9</b></li>
50+
</ul>
51+
52+
<Pre>// NET6/NET7
53+
&lt;BootstrapBlazorRoot&gt;
54+
&lt;Router&gt;&lt;Router&gt;
55+
&lt;/BootstrapBlazorRoot&gt;
56+
</Pre>
57+
</RootTemplate>
4758
</InstallContent>

src/BootstrapBlazor.Server/Locales/en-US.json

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,15 +1177,8 @@
11771177
"P1": "Please check <a href='https://learn.microsoft.com/zh-cn/aspnet/core/blazor/globalization-localization?WT.mc_id=DT-MVP-5004174' target='_blank'> before reading the following knowledge points Official document</a>"
11781178
},
11791179
"BootstrapBlazor.Server.Components.Components.InstallContent": {
1180-
"Heading": "Environmental preparation",
1181-
"P1": "Make sure the system is installed",
1182-
"P2": "or",
1183-
"P3": "or",
1184-
"P4": "Currently supported",
11851180
"P5": "Create a project using the BootstrapBlazor Project Template extension",
1186-
"P6": "you can pass",
1187-
"P7": "portal",
1188-
"P8": "After downloading and installing the extension, create a project through the extension",
1181+
"InstallByTemplate": "You can download and install the extension through <a href=\"template\">[port]</a>, and then create a project with the extension. <code>Highly recommended</code>",
11891182
"P9": "Create a project with Visual Studio",
11901183
"P10": "Step 1. Create a project",
11911184
"P11": "Open Visual Studio",
@@ -1202,16 +1195,14 @@
12021195
"P22": "Add stylesheet file",
12031196
"P23": "Add a theme style sheet to the host file",
12041197
"P24": "Need to reference BootstrapBlazor.FontAwesome package",
1205-
"P25": "Add Javascript files",
1198+
"P25": "Add Javascript files. This step can be skipped for versions later than <code>9.7.1</code>",
12061199
"P26": "add code",
12071200
"P27": "Register the BootstrapBlazor service",
12081201
"P28": "Add namespace reference",
12091202
"P29": "Add the following to",
12101203
"P30": "file so that",
12111204
"P31": "Components are recognized in the file",
1212-
"P32": "Increase",
1213-
"P33": "component to",
1214-
"P34": "in file (Replace original content with follow code)",
1205+
"AddRootText": "Add <code>BootstrapBlazorRoot</code> component into file (Replace original content with follow code)",
12151206
"P35": "under development",
12161207
"P36": "Step 3. Use components in the page",
12171208
"P37": "The last step is to use in the page",
@@ -1222,7 +1213,7 @@
12221213
"P42": "exist",
12231214
"P43": "middle",
12241215
"P44": "run the application",
1225-
"Tips2": "If you use the <code>Blazor App</code> template to create a project, please remove the default <code>Bootstrap</code> style link <code>&lt;link rel='stylesheet' href='css/bootstrap/bootstrap.min.css' /&gt;</code>. Install <b>FontAwesome</b> related resources by yourself or get the nuget package <code>BootstrapBlazor.FontAwesome</code>"
1216+
"Tips2": "If you use the blazor default template to create a project, please remove the default <code>Bootstrap</code> style link <code>&lt;link rel='stylesheet' href='css/bootstrap/bootstrap.min.css' /&gt;</code>. Install <b>FontAwesome</b> related resources by yourself or get the nuget package <code>BootstrapBlazor.FontAwesome</code>"
12261217
},
12271218
"BootstrapBlazor.Server.Components.Pages.Install_Server": {
12281219
"Title": "Server-Side Blazor Installation Tutorial",
@@ -1273,9 +1264,7 @@
12731264
"P24": "Add the following to",
12741265
"P25": "file so that",
12751266
"P26": "Components are recognized in the file",
1276-
"P27": "7. Increase",
1277-
"P28": "component to",
1278-
"P29": "in file",
1267+
"AddRootText": "7. Add <code>BootstrapBlazorRoot</code> component into <code>Routes.razor</code> file",
12791268
"P30": "under development",
12801269
"P31": "Step 3. Use components in the page",
12811270
"P32": "The last step is to use in the page <code>BootstrapBlazor</code> component and run it in the browser. E.g",

src/BootstrapBlazor.Server/Locales/zh-CN.json

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1177,16 +1177,9 @@
11771177
"P1": "阅读以下知识点前请先查看 <a href='https://learn.microsoft.com/zh-cn/aspnet/core/blazor/globalization-localization?WT.mc_id=DT-MVP-5004174' target='_blank'>微软官方文档</a>"
11781178
},
11791179
"BootstrapBlazor.Server.Components.Components.InstallContent": {
1180-
"Heading": "环境准备",
1181-
"P1": "确保系统安装",
1182-
"P2": "或者",
1183-
"P3": "或者",
1184-
"P4": "目前支持",
11851180
"P5": "使用 BootstrapBlazor Project Template 扩展创建项目",
1186-
"P6": "您可以通过",
1187-
"P7": "传送门",
1188-
"P8": "下载安装扩展后,通过扩展创建项目",
1189-
"P9": "使用 Visual Studio 创建项目 1",
1181+
"InstallByTemplate":"您可以通过 <a href=\"template\">[传送门]</a> 下载安装扩展后,通过扩展创建项目, <code>强烈推荐</code>",
1182+
"P9": "使用 Visual Studio 创建项目",
11901183
"P10": "步骤一、创建项目",
11911184
"P11": "打开 Visual Studio",
11921185
"P12": "创建一个新项目",
@@ -1202,16 +1195,14 @@
12021195
"P22": "添加样式表文件",
12031196
"P23": "在宿主文件中增加主题样式表",
12041197
"P24": "需引用 BootstrapBlazor.FontAwesome 包",
1205-
"P25": "添加 JavaScript 文件",
1198+
"P25": "添加 JavaScript 文件 <code>9.7.1</code> 版本后可跳过此步骤",
12061199
"P26": "增加代码",
12071200
"P27": "注册 BootstrapBlazor 服务",
12081201
"P28": "增加命名空间引用",
12091202
"P29": "将以下内容添加到",
12101203
"P30": "文件中,以便",
12111204
"P31": "文件中能识别组件",
1212-
"P32": "增加",
1213-
"P33": "组件到",
1214-
"P34": "文件中 (用下面代码替换原内容即可)",
1205+
"AddRootText": "增加 <code>BootstrapBlazorRoot</code> 组件到 <code>App.razor</code> 文件中 (用下面代码替换原内容即可)",
12151206
"P35": "正在玩命开发中",
12161207
"P36": "步骤三、页面中使用组件",
12171208
"P37": "最后一步是在页面中使用",
@@ -1222,7 +1213,7 @@
12221213
"P42": "在",
12231214
"P43": "中",
12241215
"P44": "运行应用程序",
1225-
"Tips2": "如果使用微软自带 <code>Blazor App</code> 模板创建工程,请移除 <code>_Layout.cshtml/index.html</code> 文件中的默认 <code>Bootstrap</code> 样式表 <code>&lt;link rel='stylesheet' href='css/bootstrap/bootstrap.min.css' /&gt;</code>。如果使用 <code>FontAwesome</code> 图标库可安装扩展包 <code>BootstrapBlazor.FontAwesome</code>"
1216+
"Tips2": "如果使用微软自带模板创建工程,请移除默认 <code>Bootstrap</code> 样式表 <code>&lt;link rel='stylesheet' href='css/bootstrap/bootstrap.min.css' /&gt;</code>。如果使用 <code>FontAwesome</code> 图标库可安装扩展包 <code>BootstrapBlazor.FontAwesome</code>"
12261217
},
12271218
"BootstrapBlazor.Server.Components.Pages.Install_Server": {
12281219
"Title": "服务器端 Blazor 安装教程",
@@ -1273,9 +1264,7 @@
12731264
"P24": "将以下内容添加到",
12741265
"P25": "文件中,以便",
12751266
"P26": "文件中能识别组件",
1276-
"P27": "7. 增加",
1277-
"P28": "组件到",
1278-
"P29": "文件中",
1267+
"AddRootText": "7. 增加 <code>BootstrapBlazorRoot</code> 组件到 <code>Routes.razor</code> 文件中",
12791268
"P30": "正在玩命开发中",
12801269
"P31": "步骤三、页面中使用组件",
12811270
"P32": "最后一步是在页面中使用 <code>BootstrapBlazor</code> 组件并在浏览器中运行它。例如:",

0 commit comments

Comments
 (0)