Skip to content

Commit 2a71df6

Browse files
committed
Using AuthorizeRouteView
1 parent 3aa2c68 commit 2a71df6

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

demo/aspnetcore6.0/v4/BlazorTransitionableRouteDemoWasm/Client/App.razor

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
<CascadingAuthenticationState>
22
<Router AppAssembly="@typeof(App).Assembly">
33
<Found Context="routeData">
4-
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
5-
<NotAuthorized>
6-
@if (context.User.Identity?.IsAuthenticated != true)
7-
{
8-
<RedirectToLogin />
9-
}
10-
else
11-
{
12-
<p role="alert">You are not authorized to access this resource.</p>
13-
}
14-
</NotAuthorized>
15-
</AuthorizeRouteView>
4+
<LayoutView Layout="@typeof(MainLayout)">
5+
<TransitionableRoutePrimary RouteData="@routeData" ForgetStateOnTransition="true">
6+
<MyAuthorizeRouteView DefaultLayout="@typeof(MyViewLayout)" />
7+
</TransitionableRoutePrimary>
8+
<TransitionableRouteSecondary RouteData="@routeData" ForgetStateOnTransition="true">
9+
<MyAuthorizeRouteView DefaultLayout="@typeof(MyViewLayout)" />
10+
</TransitionableRouteSecondary>
11+
</LayoutView>
1612
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
1713
</Found>
1814
<NotFound>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
@if (Transition?.RouteData != null)
2+
{
3+
<CascadingValue Value="Transition">
4+
<AuthorizeRouteView RouteData="@Transition.RouteData" DefaultLayout="@DefaultLayout">
5+
<NotAuthorized>
6+
@if (context.User.Identity?.IsAuthenticated != true)
7+
{
8+
<RedirectToLogin />
9+
}
10+
else
11+
{
12+
<p role="alert">You are not authorized to access this resource.</p>
13+
}
14+
</NotAuthorized>
15+
</AuthorizeRouteView>
16+
</CascadingValue>
17+
}
18+
19+
@code {
20+
[CascadingParameter]
21+
public Transition Transition { get; set; }
22+
23+
[Parameter]
24+
public Type DefaultLayout { get; set; }
25+
}

0 commit comments

Comments
 (0)