So i want a specific page to use another layout and rules but the code initialize of the mainLayout is executed event if the page doesn't use or inherit of it.
PageWithOtherLayout.razor
@layout NoMenuLayout
@page "/pagewithotherlayout"
App.razor
<CascadingAuthenticationState>
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
...
MainLayout.razor
protected async override Task OnInitializedAsync()
{
base.OnInitialized();
var user = (await AuthStat).User;
isAuth = user.Identity.IsAuthenticated;
if (!isAuth)
{
NavigationManager.NavigateTo("./login");
}
}
I didn't find anything usefull but is seem to come from the routing process of blazor.
Somewhere in your application you are loading
MainLayout.razor
. If you set the debug launch URL directly topagewithotherlayout
you will see that theOnInitializedAsync
is not called inMainLayout.razor
.I just tested this on an empty layout.
NoMenuLayout.razor