Share via

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

Nabil 6 Reputation points
Mar 26, 2023, 11:28 p.m.

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,362 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,514 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.
11,037 questions
{count} vote

1 answer

Sort by: Most helpful
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 44,171 Reputation points Microsoft Vendor
    Mar 27, 2023, 1:46 a.m.

    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.

    5 people found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.