I am looking for a solution to the "Ambiguous routes matched for" problem. I have registered Routes in AppShell.xaml.cs:
Routing.RegisterRoute("dashboard", typeof(DashboardPage));
Routing.RegisterRoute("wholesalers", typeof(WholesalersPage));
Routing.RegisterRoute("newOrder", typeof(NewOrderPage));
Routing.RegisterRoute("products", typeof(ProductsPage));
Routing.RegisterRoute("products/add", typeof(ProductAddPage));
After calling the command in ProductAddViewModel.cs
private async void OpenBarcodeReader()
{
scanPage = new ZXingScannerPage();
scanPage.OnScanResult += (result) =>
{
scanPage.IsScanning = false;
Device.BeginInvokeOnMainThread(async () =>
{
try
{
await Navigation.PopModalAsync();
}
catch (Exception ex)
{
var theproblem = ex;
}
Product.EAN = result.Text;
});
};
await Navigation.PushModalAsync(scanPage);
}
I get an error:
Ambiguous routes matched for:
//D_FAULT_TabBar10/D_FAULT_Tab9/products/D_FAULT_ProductAddPage11
matches found:
//D_FAULT_TabBar10/D_FAULT_Tab9/products/D_FAULT_ProductAddPage11,
//D_FAULT_TabBar10/D_FAULT_Tab9/products/D_FAULT_ProductAddPage11
Parameter name: uri
What I don't understand is:
a) Why am I getting this error :D
b) If PushModalAsync is executed correctly (barcode reader ppage appears, result.Text is correctly assigned to Product.EAN), then why can't I execute await Navigation.PopModalAsync(); ?
I've looked in the documentation on MS Docs, but I think my brain has already boiled over :-S
When you set the routes, if the pages are in Shell visual hierarchy, set the routes in xaml.
If the pages are not in Shell visual hierarchy, set it with
Routing.RegisterRoute. Only register your routes once using either XAML or C# not both.When you do the navigation in Shell, you could use the
Shell.Current.GoToAsyncwith absolute routes like the code below.For more details, you could refer to the MS docs: 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 the link here. I will help you to do the further troubleshooting.