.NET MAUI › Shell Navigation
How do you handle navigation lifecycle and prevent back navigation in Shell?
AdvancedAnswer
Implement IQueryAttributable for parameter handling, and override OnNavigating/OnNavigated or handle Shell.Navigating to inspect or cancel navigation (e.g., unsaved changes). Set args.Cancel() in the Navigating event, or use OnBackButtonPressed on a page to intercept hardware back.
protected override void OnNavigating(ShellNavigatingEventArgs args)
{
if (HasUnsavedChanges && args.CanCancel)
args.Cancel();
base.OnNavigating(args);
}Real-world example An edit screen prompts 'Discard changes?' by cancelling navigation when the user tries to leave with a dirty form.