How to cancel navigation to a page in .NET MAUI

Marcus Wolfe 20 Reputation points
2025-04-19T02:16:59.61+00:00

Please tell me how I can stop navigation to a page in a .NET MAUI Shell app if, for example, the user is not authorized to access the page. I have a nice authentication system and I have access and refresh tokens for communicating with the server, but can't work out how to implement basic authorization for pages in the client app. I have read as much documentation and forum threads as I can find on this topic and identified the following options, which are unsatisfactory as described:

  1. check authorization in the OnNavigatedTo event in the page, and use Shell.Current.GoToAsync() if it's not successful. This works except that the original target page opens while the navigation to the login page occurs
  2. use the OnNavigating(ShellNavigatingEventArgs args) event in the AppShell. Here I can cancel the navigation and redirect to a different page, but the AppShell doesn't have any access to the Page object of the target page so it doesn't know what authorization is required

This is my first app and I am trying to establish basic authorization like I would do for a .NET Web App. Please let me know if I have started in the entirely wrong direction and mobile apps don't normally have page authorization

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
4,084 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.