3485acf3a8
Resolve Routes.razor DefaultLayout from cascaded AuthenticationState so unauthenticated AuthBlocks pages (/account/login, /account/register) render in lean CmsHomeLayout instead of the authenticated CmsLayout shell.
38 lines
1.3 KiB
Plaintext
38 lines
1.3 KiB
Plaintext
<Router AppAssembly="typeof(App).Assembly"
|
|
AdditionalAssemblies="new[] { typeof(AuthBlocksWeb._Imports).Assembly }"
|
|
NotFoundPage="typeof(NotFound)">
|
|
<Found Context="routeData">
|
|
<AuthorizeRouteView RouteData="routeData"
|
|
DefaultLayout="@_currentLayout">
|
|
<NotAuthorized Context="authState">
|
|
@if (authState.User.Identity?.IsAuthenticated == true)
|
|
{
|
|
<RedirectToAccessDenied />
|
|
}
|
|
else
|
|
{
|
|
<RedirectToLogin />
|
|
}
|
|
</NotAuthorized>
|
|
</AuthorizeRouteView>
|
|
<FocusOnNavigate RouteData="routeData" Selector="h1" />
|
|
</Found>
|
|
</Router>
|
|
|
|
@code {
|
|
[CascadingParameter] private Task<AuthenticationState>? AuthenticationState { get; set; }
|
|
|
|
private Type _currentLayout = typeof(Layout.CmsHomeLayout);
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
if (AuthenticationState is not null)
|
|
{
|
|
var authState = await AuthenticationState;
|
|
_currentLayout = authState.User.Identity?.IsAuthenticated == true
|
|
? typeof(Layout.CmsLayout)
|
|
: typeof(Layout.CmsHomeLayout);
|
|
}
|
|
}
|
|
}
|