Blazor Server
Blazor Web App
InteractiveServer
.NET 8
builder.Services.AddScoped<NavParams>();Working Normally:
I have a Blazor Web App with 20 pages.
I use NavParams as a statebag that is injected into each page.
I use NavigationManager.NavigateTo("myNextPage") in all page navigation.
This navigation is initiated by a mouse click on a link or button.
Everything works fine.
Not Working:
I have introduced Authentication.
The home page has@attribute [Authorize]
Upon successful authentication I navigate to the next page but the NavParams.Hotel is null.
The difference is I an not initiating the navigation with a click event.
protected async override Task OnInitializedAsync(){ NavParams.Hotel = new Hotel(); NavigationManager.NavigateTo(HotelRoutes.Details, forceLoad: false);}In the target page, HotelDetails, I load the NavParams object and gather the Hotel object
protected async override Task OnParametersSetAsync(){ Hotel = NavParams.Hotel; //Hotel is null }Hotel is NULL