0

I have a very simple navigation stack consisting of a root page and then a model page on top of it. My root page is being set as the root by being the first page to be registered with Shell.

    public AppShell()
    {
        InitializeComponent();

        // opening view
        Regester<LoginPage>();

        Regester<SignUpPage>();
        ...

    }

    private void Regester<T>()
    {
        System.Diagnostics.Debug.WriteLine($"Regestering with shell : {typeof(T).Name} - {typeof(T)}");
        Items.Add(new ShellContent { Route = typeof(T).Name, ContentTemplate = new DataTemplate(typeof(T)) });
        Routing.RegisterRoute(typeof(T).Name, typeof(T));
    }
}

Then I am navigating to the model sign up page using relative routing

Shell.Current.GoToAsync("SignUpPage");

or I will use absolute routing

  Shell.Current.GoToAsync("///LogInPage/SignUpPage");

then I will attempt to navigate back in the stack using

Shell.Current.GoToAsync("..");

But I get this exception

Global routes currently cannot be the only page on the stack, so absolute routing to global routes is not supported. For now, just navigate to: LoginPage/

At the time of exception the CurrentState.Location property is this

Location = {///LoginPage/SignUpPage}

I don't understand why this is happening. This will also happen if I am further into the stack and doing something like trying to navigate back from a detail page. What do I need to do to be able to use GoToAsync("..") properly?

Sev
  • 883
  • 1
  • 14
  • 34

1 Answers1

0

Cause:

Your path ///LogInPage is invalid . Global routes currently can't be the only page on the navigation stack. Therefore, absolute routing to global routes is unsupported.

Solution:

Navigation can also be performed by specifying a valid relative URI as an argument to the GoToAsync method. The routing system will attempt to match the URI to a ShellContent object. Therefore, if all the routes in an application are unique, navigation can be performed by only specifying the unique route name as a relative URI:

await Shell.Current.GoToAsync("SignUpPage");
Lucas Zhang
  • 18,630
  • 3
  • 12
  • 22