• Home
  • Documentation
Show / Hide Table of Contents
  • Introduction
  • Getting Started
    • Download and Setup Prism
    • NuGet Packages
    • Productivity Tools
  • Commands
    • Commanding
    • Composite Commands
  • Dependency Injection
    • Getting Started
    • Registering Types
    • Platform Specific Services
    • Exception Handling
    • ContainerLocator
    • Adding a Custom Container
    • Appendix
  • Event Aggregator
  • ViewModelLocator
  • Modules
  • WPF / Uno
    • Introduction
    • Getting Started
    • Converting From Prism 7.x
    • Converting From Prism 6.x
    • View Composition
    • Region Navigation
      • About Navigation in Prism
      • Basic Region Navigation
      • View/ViewModel Participation
      • Navigating to Existing Views
      • Passing Parameters
      • Confirming Navigation
      • Controlling View Lifetime
      • Navigation Journal
    • Interactivity
      • Event To Command
    • Dialog Service
    • Advanced
      • Region Adapters
    • Legacy (Prism 6)
      • Introduction
      • Initializing
      • Managing-Dependencies
      • Modules
      • Implementing-MVVM
      • Advanced-MVVM
      • Composing-the-UI
      • Navigation
      • Communication
      • Deploying
      • Appendix-A-Glossary
      • Appendix-B-Patterns
      • Appendix-C-Prism-Library
      • Appendix-D-Extending-Prism
      • Appendix-E-Click-Once
  • .NET MAUI
    • Getting Started
    • Migrating from Prism.Forms
    • PrismAppBuilder
    • Dependency Injection
    • AppModel
      • IPageLifecycleAware
    • Behaviors
      • Introduction
      • BehaviorBase<T>
      • EventToCommandBehavior
      • PageBehaviorFactory
    • Dialogs
      • Getting Started
      • IPageDialogService
      • IDialogService
    • Navigation
      • Introduction
      • Page Navigation
      • NavigationBuilder
      • Understanding the INavigationResult
      • NavigationExceptions
      • Global Navigation Observer
      • XAML Navigation
    • Regions
      • Introduction
  • Xamarin.Forms
    • Create Your First App
    • Behaviors
      • Working with Behaviors
      • EventToCommand Behavior
      • PageBehaviorFactory
    • Dialogs
      • Dialogs
      • Page Dialog Service
      • Dialog Service
      • Styling Dialogs
    • Navigation
      • Navigation Basics
      • Passing Parameters
      • Confirming Navigation
      • Deep Linking
      • Working w/ MasterDetailPages
      • Working w/ NavigationPages
      • Working w/ TabbedPages
      • XAML Navigation
    • Application Lifecycle
    • Page Lifecycle
    • Additional Platforms
      • GTK

Global NavigationRequest Event

Out of the Box Prism's PageNavigationService (the default implementation of the INavigationService) is configured to publish events with the IEventAggregator when one of it's Navigation methods NavigateAsync, GoBackAsync, or GoBackToRootAsync are called. When it has completed, the event will fire giving you an opportunity to globally monitor these requests. What you do with the context is ultimately up to you, however it is a great place to handle Navigation Exceptions at a global level.

Handling this out of the box

As mentioned out of the Box Prism will use the IEventAggregator to publish notifications when a Navigation request is completed. To hook up to this you might add something like the following to your app:

var builder = MauiApp.CreateBuilder();
builder.UsePrismApp<App>(prism => {
    prism.OnInitialized(container => {
        var eventAggregator = container.Resolve<IEventAggregator>();
        eventAggregator.GetEvent<NavigationRequestEvent>().Subscribe(context => {
            // Handle the event
        });
    });
});

GlobalNavigationObserver

Reactive Programming has become a popular topic among .NET developers over the past several years. As a result we decided to ship the Prism.Maui.Rx package. This package is extremely lightweight and provides an easy to use extension on the PrismAppBuilder that allows you get access to the IObservable<NavigationRequestContext>.

var builder = MauiApp.CreateBuilder();
builder.UsePrismApp<App>(prism => {
    prism.AddGlobalNavigationObserver(observable => observable.Subscribe(context => {
        if(!context.Success)
        {
            // handle the error
        }
    }));
});
  • Edit on GitHub
  • Ask questions
  • Follow @PrismLib
  • Follow @BrianLagunas
  • Follow @DanJSiegel
Back to top Copyright 2015-2022 Prism