Answer:
This issue is likely related to component reuse and state not being reset properly when navigating between routes that use the same Blazor component but with different route parameters (/system/{iSysnum:int?}
).
In Blazor Server, if a component is reused across multiple routes, Blazor may not reinitialize it fully unless it’s explicitly told to do so. This behavior is especially noticeable after adding authentication or changing how state is managed.
Here’s how to resolve it:
✅ 1. Use OnParametersSetAsync()
Instead of OnInitializedAsync()
If you're currently loading data in OnInitializedAsync()
, try moving that logic to OnParametersSetAsync()
:
csharp
Copy
protected override async Task OnParametersSetAsync()
{
await LoadSystemData(iSysnum);
}
Why? OnInitializedAsync()
only runs once per component's lifetime. OnParametersSetAsync()
runs every time the route parameter (iSysnum
) changes.
✅ 2. Clear Previous State Manually (If Needed)
If your component has cached or bound data that isn’t updating, clear or reinitialize it at the beginning of OnParametersSetAsync()
to avoid stale data:
csharp
Copy
protected override async Task OnParametersSetAsync()
{
systemData = null; // clear previous data
await LoadSystemData(iSysnum);
}
✅ 3. Add Logging to Debug Parameter Handling
To confirm whether OnParametersSetAsync()
is being called, add logging or use breakpoints to track parameter changes.
✅ 4. Double-Check Authentication Flow
Though the issue began after adding Azure B2C, it’s likely coincidental — unless token-related services or HttpClient
configuration changed how your data service retrieves information.
Ensure your authenticated service call (e.g., an injected API service) properly uses the current identity context.
Summary
The page component is being reused by Blazor, and unless OnParametersSetAsync()
is used to handle dynamic route parameters, it won’t fetch new data on parameter changes. Moving your data-loading logic to that lifecycle method should fix the issue.