【发布时间】:2020-07-06 14:48:33
【问题描述】:
我有一个非常简单的导航堆栈,由一个根页面和一个位于其顶部的模型页面组成。我的根页面被设置为根页面,成为向 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("..")?
【问题讨论】:
标签: xamarin.forms navigation xamarin.shell