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

Nabil 6 Reputation points
2023-03-26T23:28:07.2466667+00:00

I am building an Xamarin Forms app for iOS and Android. I registered my routes in AppShell.xaml.cs globally like this:

**-AppShell.xaml.cs-**

Routes.Add(nameof(HousingFolderPage), typeof(HousingFolderPage));

Routes.Add(nameof(HousingFolderDetailsPage), typeof(HousingFolderDetailsPage));

In my tabbar I have a tab "MoreServicePage" which shows a list of items. So far so good.

**-MoreServicePage.cs-**

private async void ListView_ItemTapped(object sender, ItemTappedEventArgs e)

{
    await Shell.Current.GoToAsync($"HousingFolderPage");
}

Now when HousingFolderPage is showing, I have no problem navigating back from here. HousingFolderPage also shows another list, but when I push to next page, I'm not able to come back.

**-HousingFolderPage.xaml.cs-**

private async void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
{

    await Shell.Current.GoToAsync("HousingFolderDetailsPage");

}

Error message:

[0:] Shell: Failed to Navigate Back: System.ArgumentException: Ambiguous routes matched for: //D_FAULT_TabBar2/IMPL_MoreServicePage/MoreServicePage/HousingFolderPage matches found: //D_FAULT_TabBar2/IMPL_MoreServicePage/MoreServicePage/HousingFolderPage,//D_FAULT_TabBar2/IMPL_MoreServicePage/MoreServicePage/HousingFolderPage Parameter name: uri

I have only registered the routs in AppShell programmaticly (AppShell.xaml.cs) and no other places not even in the AppShell.xaml.

PS. this seems to happen everywhere where I navigate 2 pages deep, while 1 page deep works without a problem

I have created a simple Xamarin Forms Application to reproduce this issue. As you will see, you are able to navigate back from page 2, but not from page 3 to page 4 nor from page 4 to page 3.

Download test repo:

https://github.com/nabilakhlaque/Xamarin-forms-navigation-issue

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,316 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,387 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,535 questions
{count} vote

1 answer

Sort by: Most helpful
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 38,066 Reputation points Microsoft Vendor
    2023-03-27T01:46:55.8433333+00:00

    Hello,

    Ambiguous routes matched for: ....

    The reason for this problem is that you have routes defined in both XAML and C#, in fact, you only need to register the routes in one place.

    On my test, after deleting Route="Page1" in AppShell.xaml, the project worked fine.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    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.

    4 people found this answer helpful.