C
C#14mo ago
Kroks

❔ Blazor: Page loads only one time

Hello, I have an account list, each time I press on an account it loads a specific page (account overview). I set the currently selected Account in a Service, so that I can Initialize the Overview in the Overview page for that specific account. However "OnInitializedAsync" does not get triggered each time I navigate to the page, but only once. So that it works for the first account, but not for the second since it does not update. It needs to initialize some values for that specific account before it can render it.
5 Replies
Henkypenky
Henkypenky14mo ago
$code
MODiX
MODiX14mo ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat If your code is too long, post it to: https://paste.mod.gg/
friedice
friedice14mo ago
you can use onparametersetasync if your AccountId or whatever you're using to get the new account is a parameter. could set it in the page directory like so when you navigate to the other account @ page Account/{AccountId: int?}/ but yeah some additional context would be nice
Kroks
Kroks14mo ago
Could work too. I have fixed it now by loading the data before I load the page like this:
NavigationManager.NavigateTo("/loading");
StateService.CurrentData = await AccountService.GetAccountDataAsync(StateService.CurrentAccount, StateService.CurrentSocialMediaType);
NavigationManager.NavigateTo("/account-overview");
NavigationManager.NavigateTo("/loading");
StateService.CurrentData = await AccountService.GetAccountDataAsync(StateService.CurrentAccount, StateService.CurrentSocialMediaType);
NavigationManager.NavigateTo("/account-overview");
not sure if its optimal but works
Accord
Accord14mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.