.NET MAUI Shell Navigation: Routes, Query Parameters, and Navigation
.NET MAUI Shell provides a centralized navigation model based on routes. It can simplify page navigation, deep links, and passing small pieces of state between pages.
Register a Route
Routing.RegisterRoute("details", typeof(DetailsPage));
The route name becomes the stable identifier used by navigation code rather than relying on page construction at every call site.
Navigate to a Route
await Shell.Current.GoToAsync("details");
Pass Query Parameters
await Shell.Current.GoToAsync("details?id=42");
For more structured navigation, use Shell's query-property support or a navigation state object rather than placing large amounts of data in the URL-like route.
Receive Parameters
[QueryProperty(nameof(ProductId), "id")]
public partial class DetailsPage : ContentPage
{
public string ProductId { get; set; }
}
Navigation Should Stay Simple
Pass identifiers and small values through navigation. For complex application state, use a service or view-model rather than turning navigation parameters into a global data store.
Back Navigation
await Shell.Current.GoToAsync("..");
Using relative routes keeps the page decoupled from the full navigation hierarchy.
Common Mistakes
- Using inconsistent route names.
- Passing large objects through query strings.
- Mixing Shell navigation with manual page creation everywhere.
- Assuming navigation parameters are secure; they are not an authorization mechanism.
Conclusion
Shell navigation works best when routes remain predictable and navigation carries only the small amount of state needed to identify the destination.
Ask AlgoLassi and get an answer plus the tutorials worth studying next.
đŦ Comments
Sign in with Google to publish immediately, or comment anonymously and wait for approval.
Comments will appear here when available.