INavigatingAware.OnNavigatingTo was first introduced to Prism to assist developers perform initialization logic similar to the ViewWillAppear.
To help better visualize this the events look something like this within the NavigationService:
- Create the Page
- Set the ViewModelLocator.Autowire property if it is null
- Apply any behaviors from the PageBehaviorFactory
- Call IConfirmNavigation.CanNavigate (and it's async counterpart) on the Page/ViewModel we're navigating away from
- Call INavigatingAware.OnNavigatingTo
- Push the page onto the NavigationStack
- Call INavigatedAware.OnNavigated{From|To}
BREAKING CHANGE
Now, all of that said, we have had a tremendous amount of feedback on INavigatingAware (the essence of this very question), as a result over the overwhelming feedback from the Prism community INavigatingAware has been a hard obsolete in Prism 7.2. This means that it was removed from INavigationAware, and will throw a compile time error if you directly implement it. For those times where you got it for free from INavigationAware, it simply will not be called. Moving forward, we have introduced a series of interfaces to make this easier and more self documenting as to the intent.
- IInitialize.Initialize
- IInitializeAsync.InitializeAsync
- IAutoInitialize
The new IInitialize interface is the direct replacement for INavigatingAware. We have long gotten feedback that people would like the ability to perform async tasks during initialization. The issue here is that this can cause a very noticeable delay in Navigation similar to IConfirmNavigationAsync. If you use either of those async interfaces, you will need to be sure to include some sort of busy/loading overlay on your screen.
Finally the fun one... IAutoInitialize is simply a marker interface. If set on your ViewModel it will automatically attempt to set any properties in your ViewModel based on what's contained in the NavigationParameters. This is case insensitive, and there is an additional attribute that you can mark on your properties in the case your property name is something like Model and your parameter name is monkey.