Skip to content
10 changes: 10 additions & 0 deletions src/BootstrapBlazor.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@

var app = builder.Build();

app.UseStatusCodePages(context =>
{
var response = context.HttpContext.Response;
if(response.StatusCode == 404)
{
response.Redirect("/");
}
return Task.CompletedTask;
});

// 启用本地化
var option = app.Services.GetService<IOptions<RequestLocalizationOptions>>();
if (option != null)
Expand Down
9 changes: 4 additions & 5 deletions src/BootstrapBlazor/Components/Layout/Layout.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@attribute [BootstrapModuleAutoLoader(JSObjectReference = true)]

<CascadingValue Value="this" IsFixed="true">
@if (IsInit)
@if (_init)
{
@if (IsAuthenticated)
{
Expand Down Expand Up @@ -118,11 +118,10 @@
@<main class="@MainClassString">
@if (UseTabSet)
{
<Tab ClickTabToNavigation="ClickTabToNavigation"
ShowExtendButtons="ShowTabExtendButtons" ShowClose="ShowTabItemClose" AllowDrag="AllowDragTab"
AdditionalAssemblies="@AdditionalAssemblies" NotFoundTabText="@NotFoundTabText"
<Tab ClickTabToNavigation="ClickTabToNavigation" AdditionalAssemblies="@AdditionalAssemblies"
ShowExtendButtons="ShowTabExtendButtons" ShowClose="ShowTabItemClose" AllowDrag="AllowDragTab"
DefaultUrl="@TabDefaultUrl" ExcludeUrls="@ExcludeUrls" IsOnlyRenderActiveTab="IsOnlyRenderActiveTab"
Body="@Main" NotAuthorized="NotAuthorized!" NotFound="NotFound!">
Body="@Main" NotAuthorized="NotAuthorized!" NotFound="NotFound!" NotFoundTabText="@NotFoundTabText">
</Tab>
}
else
Expand Down
10 changes: 5 additions & 5 deletions src/BootstrapBlazor/Components/Layout/Layout.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,19 @@ public partial class Layout : IHandlerException
public RenderFragment? Side { get; set; }

/// <summary>
/// 获得/设置 NotAuthorized 模板
/// 获得/设置 NotAuthorized 模板 默认 null NET6.0/7.0 有效
/// </summary>
[Parameter]
public RenderFragment? NotAuthorized { get; set; }

/// <summary>
/// 获得/设置 NotFound 模板
/// 获得/设置 NotFound 模板 默认 null NET6.0/7.0 有效
/// </summary>
[Parameter]
public RenderFragment? NotFound { get; set; }

/// <summary>
/// 获得/设置 NotFound 标签文本
/// 获得/设置 NotFound 标签文本 默认 null NET6.0/7.0 有效
/// </summary>
[Parameter]
[NotNull]
Expand Down Expand Up @@ -337,7 +337,7 @@ public partial class Layout : IHandlerException
[Inject]
private IAuthorizationService? AuthorizationService { get; set; }

private bool IsInit { get; set; }
private bool _init { get; set; }

/// <summary>
/// <inheritdoc/>
Expand Down Expand Up @@ -387,7 +387,7 @@ protected override async Task OnInitializedAsync()
IsAuthenticated = true;
}

IsInit = true;
_init = true;
}

/// <summary>
Expand Down
18 changes: 9 additions & 9 deletions src/BootstrapBlazor/Components/Tab/Tab.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,24 @@ public partial class Tab : IHandlerException
public RenderFragment? ChildContent { get; set; }

/// <summary>
/// 获得/设置 NotAuthorized 模板
/// 获得/设置 NotAuthorized 模板 默认 null NET6.0/7.0 有效
/// </summary>
[Parameter]
public RenderFragment? NotAuthorized { get; set; }

/// <summary>
/// 获得/设置 NotFound 模板
/// 获得/设置 NotFound 模板 默认 null NET6.0/7.0 有效
/// </summary>
[Parameter]
public RenderFragment? NotFound { get; set; }

/// <summary>
/// 获得/设置 NotFound 标签文本 默认 null NET6.0/7.0 有效
/// </summary>
[Parameter]
[NotNull]
public string? NotFoundTabText { get; set; }

/// <summary>
/// 获得/设置 TabItems 模板
/// </summary>
Expand Down Expand Up @@ -179,13 +186,6 @@ public partial class Tab : IHandlerException
[Parameter]
public Func<TabItem, Task>? OnClickTabItemAsync { get; set; }

/// <summary>
/// 获得/设置 NotFound 标签文本
/// </summary>
[Parameter]
[NotNull]
public string? NotFoundTabText { get; set; }

/// <summary>
/// 获得/设置 关闭当前 TabItem 菜单文本
/// </summary>
Expand Down