Replies: 2 comments
-
The route generator doesn't register any routes automatically. You still have to do this yourself, e.g. when using MAUI it would look like this: foreach (var route in Routes.RouteTypeMap)
{
Routing.RegisterRoute(route.Key, route.Value);
} Hence, you could just modify that loop to skip routes that are already registered or that you know will be registered by Shell itself. You can also register routes differently outside of the loop: Routing.RegisterRoute("//Main", Routes.RouteTypeMap[Routes.MainPage]); |
Beta Was this translation helpful? Give feedback.
-
Sorry, I wasn't trying to suggest RouteGenerator currently registered routes, it's just that doing so was in "Future Ideas" and the interaction between routes in All that said, if you don't abuse the routing mechanism RouteGenerator works well, so thanks. I've even gone as far as to use the generated routes in XAML to improve reference checking (the VS "code search" feature will find them in XAML). For example (the app in this case is called DivisiBill): <Shell xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
...
xmlns:view="clr-namespace:DivisiBill.Views"
xmlns:local="clr-namespace:DivisiBill"
...
<ShellContent Title="Items" ContentTemplate="{DataTemplate view:LineItemsPage}" Route="{x:Static local:Routes.LineItemsPage}"/>
<ShellContent Title="Totals" ContentTemplate="{DataTemplate view:TotalsPage}" Route="{x:Static local:Routes.TotalsPage}"/>
</Shell> |
Beta Was this translation helpful? Give feedback.
-
While the idea of automatically registering routes seems like a good one in principle, the Shell object itself registers the pages used in ShellContent objects, so in the typical AppShell.xaml you might see something like:
Then in AppShell.xaml.cs there would be
Routing.RegisterRoute("details", typeof(DetailsPage))
.You would probably not want to re-register the pages already registered by
ShellContent
items unless you want to be able to navigate to new instances of them, which is what registering them seems to enable. In the example above I'd speculate most people want to useShell.Current.GoToAsync("//Main")
rarelyShell.Current.GoToAsync("Main")
.So, bottom line, you probably need to distinguish the two types of pages which isn't terribly hard to do (by name suffix, for example), but it's probably worth some thought.
Beta Was this translation helpful? Give feedback.
All reactions