!88 feat(#I3S4R1): 增加未授权自动跳转功能

* feat: 增加未授权自动跳转功能
* refactor: 重构代码
This commit is contained in:
Argo 2021-05-20 12:26:53 +08:00
parent 4b39a2da63
commit 361037cdbd
6 changed files with 22 additions and 15 deletions

View File

@ -1,5 +1,5 @@
<CascadingAuthenticationState>
<Router AppAssembly="@typeof(Program).Assembly" AdditionalAssemblies="new[] { typeof(MainLayout).Assembly }" PreferExactMatches="@true">
<Router AppAssembly="@typeof(MainLayout).Assembly" PreferExactMatches="@true">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
<NotAuthorized>

View File

@ -5,7 +5,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="BootstrapBlazor" Version="5.0.30" />
<PackageReference Include="BootstrapBlazor" Version="5.0.31-beta03" />
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="5.0.6" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.6" />
</ItemGroup>

View File

@ -1,4 +1,5 @@
@page "/Home/Index"
@page "/"
@page "/Home/Index"
<h1>Hello, world!</h1>

View File

@ -2,7 +2,6 @@
using BootstrapBlazor.Components;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Components.Routing;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@ -30,6 +29,8 @@ namespace Bootstrap.Client.Blazor.Shared.Shared
private bool ShowFooter { get; set; } = true;
private bool IsAuthenticated { get; set; }
[NotNull]
private List<MenuItem>? Menus { get; set; }
@ -82,7 +83,6 @@ namespace Bootstrap.Client.Blazor.Shared.Shared
{
UserName = state.User.Identity.Name;
DisplayName = UserHelper.RetrieveUserByUserName(UserName)?.DisplayName;
}
// 模拟异步线程切换,正式代码中删除此行代码
await Task.Yield();
@ -92,8 +92,11 @@ namespace Bootstrap.Client.Blazor.Shared.Shared
{
[""] = "Index"
};
// 获取登录用户菜单
Menus = GetMenus();
}
}
private List<MenuItem> GetMenus()
{

View File

@ -1,6 +1,8 @@
@using BootstrapBlazor.Components
@using Bootstrap.Client.Blazor.Shared.Shared
@using BootstrapBlazor.Components
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.Authorization
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web

View File

@ -1,4 +1,5 @@
@page "/"
@using Bootstrap.Client.Blazor.Shared
@namespace Bootstrap.Client.Blazor.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@{