Search code examples
.netxamarin.formsapp-shell

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


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


Solution

  • There is an similar issue abaout GotoAsync build in back button does not go back to previous page, when working with 3 or more pages.

    And the cause for this problem is you register the first page both in the xaml and the AppShell.cs.

    I have tested the repo sample you posted on the github. When I deleted the Route="Page1" in the <ShellContent Route="Page1" ContentTemplate="{DataTemplate local:Page1}" />. The navigation worked well.

    So you can check the if there is any page you register route both in the AppShell.xams and AppShell.xaml.cs or not.