I have a Blazor Hybrid Maui app that uses websocketclient. When user navigates away from the page, I need to gracefully close the connection. I use OnLocationChanged(). That should work for you as well.
private void OnLocationChanged(object? sender, LocationChangedEventArgs e)
{
if (e.IsNavigationIntercepted)
{
// Handle the page closing event here
ws.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, "Page Closing", CancellationToken.None);
}
}