Confirming or canceling navigation
As users interact with our application, there may be moments when they’re about to navigate away from a page containing unsaved changes or important input. To prevent potential data loss, it’s essential to prompt for confirmation before allowing such navigation. Let’s see how we could build this by leveraging the NavigationService
that we built in the previous chapter:
- Let’s start by adding the following interface called
INavigatable
to theNavigation
folder of theRecipes.Client.Core
project:public interface INavigatable { Task<bool> CanNavigateFrom(NavigationType navigationType); }
ViewModels that want to control whether the user is able to navigate can implement this interface. This is analogous to the other interfaces we introduced in the context of navigation, such as the
INavigatedFrom
,INavigatedTo
, andINavigationParameterReceiver
interfaces. - Extend the
INavigationInterceptor...