When navigating to ItemDetailPage page with query paramenter "id" I get below error (it works without paramenter)
System.ArgumentException: 'unable to figure out route for: //items/details?id=3ca6c981-52d6-4875-ae74-2e20fd878b77
Parameter name: uri'
ItemDetailPage is not a part of the Shell hierarchy and therefore registered in the AppShell constructor:
Routing.RegisterRoute("//items/details", typeof(ItemDetailPage));
In the ItemDetailPage I have added QueryProperty:
[QueryProperty("ItemId", "id")]
public partial class ItemDetailPage : ContentPage
and added ItemId property to the class:
private string itemId;
public string ItemId { get { return itemId; } set { itemId = Uri.UnescapeDataString(value); } }
I navigate to the page by calling:
await Shell.Current.GoToAsync($"//items/details?id={item.Id}");
What am I missing to make this work?
If I remove the "id" parameter from the GoToAsync call it navigates, but without id.
Thank you in advance
Answers
“//” means you want to use absolute routes to navigate: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/shell/navigation#absolute-routes.
You'd better not consume it in your route's registration. Rename it like:
And you could successfully navigate to it with a parameter:
But the documentation says that absolute routes should work as well?
https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/shell/navigation#pass-data
Might actually be this bug: https://github.com/xamarin/Xamarin.Forms/issues/6829
Yes, you can use an absolute route. But you should not include the special identifier("//") in your route name when you registered it.
If you want to use absolute you can try
But you still need to modify your registration to the correct format as the sample: https://github.com/xamarin/xamarin-forms-samples/blob/master/UserInterface/Xaminals/Xaminals/AppShell.xaml.cs
Hi LandLu,
I removed the leading "//" from my registration, but it didn't work before I added "Route" to my ShellContent in AppShell.xaml
Thank you for your help!
If you want items to be your parent route you have to define it to your
ShellContent
.