I have blazor app running WASM (not server) on .NET 5, version 5.0.3. I would like to be able to detect when a user navigates away from the site or closes the browser. The dispose only seems to fire when navigating within the app itself (i.e. the page or control is disposed due to a navigation).
Here is my page markup, I have also tried implementing IAsyncDisposable with the same result:
@page "/"
@using Microsoft.AspNetCore.Authorization
@attribute [Authorize]
@inject NavigationManager NavigationManager
@inject IHubManager HubManager
@implements IDisposable
<Tabs />
@code{
public void Dispose()
{
_ = HubManager.DisposeAsync();
}
}
According to some of the posts I have read here, this approach works when using the server version of blazor, can anyone tell me if there is another approach I need to use with WASM?
The goal is to be able to close / dispose a connection to my signalR hub at the point the user leaves the site.