Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bug? System.ArgumentException: 'unable to figure out route for:

Error

System.ArgumentException: 'unable to figure out route for: //RegisterPage Parameter name: uri' System.ArgumentException: 'unable to figure out route for: //LogoPage Parameter name: uri'

What is wrong? It cant figure out the route...?

XAML

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d"
             x:Class="MyApp.Views.WelcomePage"
             Shell.NavBarIsVisible="False">
    <ContentPage.Content>
        <StackLayout Padding="10,0,10,0" VerticalOptions="Center">
            <Button VerticalOptions="Center" Text="Register" Command="{Binding RegisterCommand}"/>
            <Button VerticalOptions="Center" Text="Login" Command="{Binding LoginCommand}"/>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

Code behind

[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class WelcomePage : ContentPage
{
    public WelcomePage()
    {
        InitializeComponent();
        this.BindingContext = new WelcomeViewModel();
    }
}

WelcomeViewModel.cs

public Command RegisterCommand { get; }
public Command LoginCommand { get; }

public WelcomeViewModel()
{
    RegisterCommand = new Command(OnRegisterClicked);
    LoginCommand = new Command(OnLoginClicked);
}

private async void OnRegisterClicked(object obj)
{
    await Shell.Current.GoToAsync($"//{nameof(RegisterPage)}");
}

private async void OnLoginClicked(object obj)
{
    await Shell.Current.GoToAsync($"//{nameof(LoginPage)}");
}
like image 813
001 Avatar asked Nov 25 '20 10:11

001


1 Answers

Your need to register a route for each page you are willing to navigate into it using Shell.Current.GoToAsync(), with this way you can also clarify your pages hierarchy:

    <FlyoutItem FlyoutDisplayOptions="AsMultipleItems">

        <ShellContent Title="RegisterPage"
                      Route="RegisterPage"
                      ContentTemplate="{DataTemplate local:RegisterPage}"/>

        <ShellContent Title="LoginPage"
                      Route="LoginPage"
                      ContentTemplate="{DataTemplate local:LoginPage}"/>

        <ShellContent Title="Page3"
                      ContentTemplate="{DataTemplate local:Page3}"/>

    </FlyoutItem>

You can also register the route using Routing.RegisterRoute() in the code if you prefer, as long as it runs before a route is invoked: Routing.RegisterRoute("//Page3", typeof(Page3));

Microsoft Documentation

For more details: Shell Navigation

like image 56
Cfun Avatar answered Oct 21 '22 14:10

Cfun