I have a script that does a while loop and does some requests
<p>Result @Content</p>
private string Content;
public async Task StartAsync()
{
while(!taskCanel) {
Content = await webSocket.SendAsync(..);
StateHasChanged();
await Task.Delay(15000);
}
}
but whenever I switch another page with my navbar then go back to this page it reset everything like it creates a new instance of my razor page.
How can I navigate to the page without losing all states and content?
While you are navigating to another page all variables from the current page should be disposed. It is the standard procedure. The state management works with a different approach. If you want to retain the state of the current page then you have to subscribe to the changes in a global object and pull the change onInit hook or onafterrender hook. There is many more library for state management. Some of them are introduced here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With