As mentioned before, routes can be added declaratively in the XAML (Route="MyDucks") or in code, as shown here next:
- In the News project, open the MainShell.xaml.cs file.
- Add the following lines of code marked in bold:
using News.Views;
using Xamarin.Forms;
namespace News
{
public partial class MainShell
{
public MainShell()
{
InitializeComponent();
Routing.RegisterRoute("articleview",
typeof(ArticleView));
}
}
}
The RegisterRoute() method takes two arguments; the first is the route we want to use, and it's the one that we specify in the NavigateTo() calls. The second is the type of the page (view) that we want to create, and in our case, we want to create an ArticleView.
Cool! That wraps it up. The app should now run, and you should be able to navigate to the article from any of the CollectionViews. Good work!