diff --git a/src/BootstrapBlazor/Components/Tab/TabLink.razor b/src/BootstrapBlazor/Components/Tab/TabLink.razor
index 64e409c84..be8c30b28 100644
--- a/src/BootstrapBlazor/Components/Tab/TabLink.razor
+++ b/src/BootstrapBlazor/Components/Tab/TabLink.razor
@@ -1,7 +1,4 @@
@namespace BootstrapBlazor.Components
@inherits BootstrapComponentBase
-@if (ChildContent != null)
-{
- @ChildContent
-}
+@RenderChildContent()
diff --git a/src/BootstrapBlazor/Components/Tab/TabLink.razor.cs b/src/BootstrapBlazor/Components/Tab/TabLink.razor.cs
index d2da82ad3..4137e2179 100644
--- a/src/BootstrapBlazor/Components/Tab/TabLink.razor.cs
+++ b/src/BootstrapBlazor/Components/Tab/TabLink.razor.cs
@@ -65,5 +65,27 @@ namespace BootstrapBlazor.Components
TabItemOptions.Text = Text;
TabItemOptions.Closable = Closable;
}
+
+ private RenderFragment RenderChildContent() => builder =>
+ {
+ var index = 0;
+ if (ChildContent == null)
+ {
+ if (!string.IsNullOrEmpty(Icon))
+ {
+ builder.OpenElement(index++, "i");
+ builder.AddAttribute(index++, "class", Icon);
+ builder.CloseElement();
+ }
+ if (!string.IsNullOrEmpty(Text))
+ {
+ builder.AddContent(index++, Text);
+ }
+ }
+ else
+ {
+ builder.AddContent(index++, ChildContent);
+ }
+ };
}
}
diff --git a/src/BootstrapBlazor/Extensions/NavigationManagerExtensions.cs b/src/BootstrapBlazor/Extensions/NavigationManagerExtensions.cs
index 8b7d5a2e8..f7ea741e5 100644
--- a/src/BootstrapBlazor/Extensions/NavigationManagerExtensions.cs
+++ b/src/BootstrapBlazor/Extensions/NavigationManagerExtensions.cs
@@ -6,30 +6,29 @@ using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.DependencyInjection;
using System;
-namespace BootstrapBlazor.Components
+namespace BootstrapBlazor.Components;
+
+///
+/// NavigationManager 扩展方法
+///
+public static class NavigationManagerExtensions
{
///
- ///
+ /// 导航并添加 TabItem 方法
///
- public static class NavigationManagerExtensions
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static void NavigateTo(this NavigationManager navigation, IServiceProvider provider, string url, string text, string? icon = null, bool? closable = null)
{
- ///
- /// 导航并添加 TabItem 方法
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- public static void NavigateTo(this NavigationManager navigation, IServiceProvider provider, string url, string text, string? icon = null, bool? closable = null)
- {
- var option = provider.GetRequiredService();
- option.Text = text;
- option.Icon = icon;
- option.IsActive = true;
- option.Closable = closable ?? true;
- navigation.NavigateTo(url);
- }
+ var option = provider.GetRequiredService();
+ option.Text = text;
+ option.Icon = icon;
+ option.IsActive = true;
+ option.Closable = closable ?? true;
+ navigation.NavigateTo(url);
}
}