0

我有一个非常简单的导航堆栈,由一个根页面和一个位于其顶部的模型页面组成。我的根页面通过成为向 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));
    }
}

然后我使用相对路由导航到模型注册页面

Shell.Current.GoToAsync("SignUpPage");

或者我将使用绝对路由

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

然后我将尝试使用

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

但我得到了这个例外

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/

在异常时 CurrentState.Location 属性是这个

Location = {///LoginPage/SignUpPage}

我不明白为什么会这样。如果我进一步深入堆栈并执行诸如尝试从详细信息页面导航回来的操作,也会发生这种情况。我需要做什么才能正确使用 GoToAsync("..")?

4

1 回答 1

0

原因:

您的路径///LogInPage无效。全球路线目前不能是导航堆栈上的唯一页面。因此,不支持到全局路由的绝对路由。

解决方案:

也可以通过将有效的相对 URI 指定为 GoToAsync 方法的参数来执行导航。路由系统将尝试将 URI 与 ShellContent 对象匹配。因此,如果应用程序中的所有路由都是唯一的,则可以通过仅将唯一的路由名称指定为相对 URI 来执行导航:

await Shell.Current.GoToAsync("SignUpPage");
于 2020-07-07T03:08:25.763 回答