@inherits LayoutComponentBase @implements IDisposable @* The page and its menu. The overlays it holds (dialogs, menus, sheets: IDOverlayHost, cascaded) close with the phone's Back button: while one is open, Back closes the newest instead of leaving the page; a link followed or the app's own navigation closes them all and goes on. *@
@Body
@code { [Inject] OverlayService Overlays { get; set; } [Inject] NavigationManager Navigation { get; set; } [Inject] AppStatusService Status { get; set; } IDisposable changing; protected override void OnInitialized() => changing = Navigation.RegisterLocationChangingHandler(OnLocationChanging); async ValueTask OnLocationChanging(LocationChangingContext context) { var back = !context.IsNavigationIntercepted && Status.TookBack(); if (!Overlays.HasOpen) return; if (back) { context.PreventNavigation(); await Overlays.CloseTop(context.CancellationToken); return; } await Overlays.CloseAll(context.CancellationToken); } public void Dispose() => changing?.Dispose(); }