Xamarin.Android - AppShell- Failed to Navigate Back, Ambiguous routes matched for.... but i've only registered routes once.

zwooding 21 Reputation points
2021-05-23T22:46:37.637+00:00

Hello, first time posting so I apologize if I leave out important info or break any posting rules.

I am building an Xamarin Forms app for iOS and Android.

I registered my routes in AppShell.xaml.cs globally like this:

Routing.RegisterRoute($"{nameof(HomeViewPage)}", typeof(HomeViewPage));
Routing.RegisterRoute($"{nameof(AboutPage)}", typeof(AboutPage));
Routing.RegisterRoute($"{nameof(ServiceViewPage)}", typeof(ServiceViewPage));         
    

I then navigate just fine like this:

//navigate from Home page to About page
await Shell.Current.GoToAsync("//HomeViewPage/AboutPage");

//navigate from About page to Services page
await Shell.Current.GoToAsync("//HomeViewPage/AboutPage/ServicesViewPage");

and I have navigated just fine like this:

await Shell.Current.GoToAsync(nameof(AboutPage));

 await Shell.Current.GoToAsync(nameof(ServiceViewPage));

This all works fine on both iOS and Android.

Once I try to navigate back to the about page by tapping the Back button on Android I get the following error:

[0:] Shell: Failed to Navigate Back: System.ArgumentException: Ambiguous routes matched for: //D_FAULT_FlyoutItem4/IMPL_HomeViewPage/HomeViewPage/AboutPage matches found: //D_FAULT_FlyoutItem4/IMPL_HomeViewPage/HomeViewPage/AboutPage,//D_FAULT_FlyoutItem4/IMPL_HomeViewPage/HomeViewPage/AboutPage

I haven't registered any other routes other than in AppShell.xaml.cs as stated in this posts.

I looked in to the bug posted in the Xamarin github here. This is a little different problem but I found another page that said this problem is the same as the bug posted on the github. The bug is said to have been solved in version 5.0.0 of Xamarin.Forms and I am using 5.0.0.2012.

This problem is only on Android. iOS works as expected.

Is this still a problem with Xamarin or am I doing something wrong?

Any info would be very helpful!

Thank you!

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,254 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 63,921 Reputation points Microsoft Vendor
    2021-05-24T02:17:57.197+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    I notice you register ServiceViewPage in the AppShell.xaml.cs with following code.

       Routing.RegisterRoute($"{nameof(ServiceViewPage)}", typeof(ServiceViewPage));  
    

    But when you navigated page with name of Service s ViewPage, add S in your following code.

       await Shell.Current.GoToAsync("//HomeViewPage/AboutPage/ServicesViewPage");  
    

    And you used different way to navigate. Following way is Absolute routes, This navigates to the page for the ServicesViewPage route, with the route being defined on a ShellContent object. The ShellContent object that represents the ServicesViewPageroute is a child of a FlyoutItem object, whose route is AboutPage or HomeViewPage. Did you define it in your appshell.xaml

       await Shell.Current.GoToAsync("//HomeViewPage/AboutPage/ServicesViewPage");  
    

    Here is Relative routes with await Shell.Current.GoToAsync(nameof(ServiceViewPage));, I recommand you to use this way to make a test.

    You can see this article about it.

    https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/shell/navigation#absolute-routes

    If this issue is still existed, could you share your demo to GitHub, then post demo thread to here. I will help you to do some further troubleshooting.

    Best Regards,

    Leon Lu


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


2 additional answers

Sort by: Most helpful
  1. Andy James - CB 1 Reputation point
    2021-06-22T21:14:19.53+00:00

    Posted a message asking for more explanation but it just took a while to sink in (moron!)

    Thank you guys! I can now rest again and stop crying

    0 comments No comments

  2. Vitor Bedin 1 Reputation point
    2021-09-09T02:54:49.893+00:00

    Same problem here... how did you fixed it?

    Cheers[]

    0 comments No comments