Description
It would be cool to have the ability to check whether a certain route has already been registered.
In my scenario I am doing route registration automatically via a navigation service and extended ContentPage.
However, due to the current API and behavior of .NET MAUI, there is a scenario in which the code attempts to register the same route twice.
I don't really want to catch exceptions and check for string equality since it would also swallow developer's mistakes.
I'd rather have an API to check for a specific route whether it has already been registered or not before calling Routing.RegisterRoute.
Alternatively Routing.RegisterRoute could have a parameter to set whether it should throw on duplicate registration attempt or not.
Public API Changes
public static void IsRouteRegistered(string route, RouteFactory factory, bool throwOnDuplicateRegistration = true)
public static void IsRouteRegistered(string route, Type type, bool throwOnDuplicateRegistration = true)
or
public static void RegisterRoute(string route,
Intended Use-Case
I am using Shell with Flyout and want a specific page to be created on app startup.
However, I have an extended ContentPage where I am passing a ViewModel instance as constructor parameter to be able to automatically resolve it using the IServiceProvider during Shell navigation.
To still be able to pre-create the page during app startup, I am now setting the BindingContext via XAML and in OnBindingContextChanged registering the route to the page.
The OnBindingContextChanged, however, does get called more than once and therefor can throw an exception on attempting to register the route.
Description
It would be cool to have the ability to check whether a certain route has already been registered.
In my scenario I am doing route registration automatically via a navigation service and extended
ContentPage.However, due to the current API and behavior of .NET MAUI, there is a scenario in which the code attempts to register the same route twice.
I don't really want to catch exceptions and check for string equality since it would also swallow developer's mistakes.
I'd rather have an API to check for a specific route whether it has already been registered or not before calling
Routing.RegisterRoute.Alternatively
Routing.RegisterRoutecould have a parameter to set whether it should throw on duplicate registration attempt or not.Public API Changes
or
Intended Use-Case
I am using
ShellwithFlyoutand want a specific page to be created on app startup.However, I have an extended
ContentPagewhere I am passing a ViewModel instance as constructor parameter to be able to automatically resolve it using theIServiceProviderduring Shell navigation.To still be able to pre-create the page during app startup, I am now setting the
BindingContextvia XAML and inOnBindingContextChangedregistering the route to the page.The
OnBindingContextChanged, however, does get called more than once and therefor can throw an exception on attempting to register the route.