I am making a website using Blazor/razor where the login page has a different layout than my default layout. I know I have to use the @layout tag at the top of the page to specify that I am using a different layout, but the problem is that when the page opens, it seems as if the default layout is used for a split second before it changes to use my specified layout. Any suggestions as to how to stop that from happening?
1 Answer
The issue was the call for await base.OnInitializedAsync() was being done in the incorrect order. In my MainLayout.razor file, there is an OnInitializedAsync method containing the aforementioned await call. I also have some logic checking if a user has been authenticated to use the website (logged in), to be redirected to the loggin page if not. By making sure that the await base.OnInitializedAsync() call is after that logic, the page stopped rendering the incorrect layout before loading the "overridden" layout. From what I can gather, this is because the await call contains the base keyword which has something to do with layouts, so having this call before my redirection logic was initializing the page and rendering the default layout of the page before any logic was done.
3 Comments
await base.OnInitializedAsync(); should just be deleted.