Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with implicit vs explicit Shell Routing #17629

Open
hansmbakker opened this issue Sep 25, 2023 · 6 comments
Open

Issue with implicit vs explicit Shell Routing #17629

hansmbakker opened this issue Sep 25, 2023 · 6 comments
Labels
area-controls-shell Shell Navigation, Routes, Tabs, Flyout s/triaged Issue has been reviewed t/bug Something isn't working
Milestone

Comments

@hansmbakker
Copy link

Description

I have an issue with route registration in MAUI Shell.

First of all, it is possible to define routes on different places, having a different effect. This different result is super confusing.

  1. in AppShell.xaml using the Route attribute of ShellItems. This results in an object in Shell.Current.Children having an Route property with value IMPL_{value of Route attribute in AppShell.xaml}. This is an implicit route according to the logic in Routing.cs. It does not show up in Routing.s_routes.
  2. in C# using Routing.RegisterRoute(route, typeof(TView)), or using something like AddSingletonWithShellRoute from MAUI Community Toolkit (which calls Routing.RegisterRoute(route, typeof(TView)) under the hood). This does result in a route registered in Routing.s_routes. I guess you could call this an explicit route then, although it is not called as such in the code.

Another, even more annoying part is that

  • when a route is registered as implicit route, it is possible to call Shell.Current.GoToAsync("///LoadingPage") on it without a problem
  • when a route is registered as explicit route, calling Shell.Current.GoToAsync("///LoadingPage") throws an exception:

    System.Exception: 'Global routes currently cannot be the only page on the stack, so absolute routing to global routes is not supported. For now, just navigate to: /LoadingPage'

This means that you cannot use Routing.RegisterRoute(route, typeof(TView)) nor the AddSingletonWithShellRoute convenience function to register routes if you want to do an absolute navigation.

Documentation for this item is missing, and from the code it is not intuitive what to expect with what approach.

Steps to Reproduce

Link to public reproduction project repository

No response

Version with bug

8.0.0-rc.1.9171

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

No response

Did you find any workaround?

Set the route directly in AppShell.xaml using the Route parameter of a ShellItem separately from the dependency injection registration.

Relevant log output

No response

@hansmbakker hansmbakker added the t/bug Something isn't working label Sep 25, 2023
@hansmbakker
Copy link
Author

The question is - can the difference between implicit and explicit routing please be documented, including some words on the intended usage of each.

Also: Is the limitation (exception on navigation) when using explicit registration an artificial one, or is it there for a reason?

Can the community toolkit's DI registration methods be used in such a way that this exception does not happen?

@Eilon Eilon added the area-controls-shell Shell Navigation, Routes, Tabs, Flyout label Sep 25, 2023
@RoiChen001 RoiChen001 added the s/triaged Issue has been reviewed label Feb 29, 2024
@jfversluis
Copy link
Member

@PureWeen thoughts?

@James-McMenamin

This comment was marked as off-topic.

@SuperCorks
Copy link

I agree with this, Shell routing for this case seems to be broken.

@mattleibow mattleibow added this to the Backlog milestone Nov 21, 2024
@mattleibow
Copy link
Member

@PureWeen thoughts?

@Ghostbird
Copy link
Contributor

Ghostbird commented Feb 7, 2025

For those looking into this. I'm running into this as well. It seems any explicit route registration is incompatible with constructor injection. It'll always throw with "no public parameterless constructor" for the routed page, instead of resolving that type from the service provider.

Here's a small reproduction

Off-topic: This reproduction also showcases another issue, that I haven't found documented. I haven't managed to figure out how you can start a Shell based app on an explicit route, instead of an implicit shell item. My current approach is to register a blank content page as default shell item, and immediately call GoToAsync in OnAppearing, but this is at best an inelegant approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-shell Shell Navigation, Routes, Tabs, Flyout s/triaged Issue has been reviewed t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

9 participants