So I have a login page and a main page. On the launch of the app, I want to check to see if the app has a token saved and if not launch to login page.
In WP8.1 Silverlight I used to use
RootFrame.Navigating += new NavigatingCancelEventHandler(RootFrame_Navigating);
and then
void RootFrame_Navigating(object sender, NavigatingCancelEventArgs e)
{
if (e.Uri.ToString().Contains("/Pages/MainPage.xaml") != true)
{
return;
}
if (token != null)
{
return;
}
else if (token == null)
{
e.Cancel = true;
RootFrame.Dispatcher.BeginInvoke(delegate
{
RootFrame.Navigate(new Uri("/Pages/LoginPage.xaml", UriKind.Relative));
});
}
}
What's the best way to do this in a WP8.1 runtime app?
In your App.xaml.cs under the OnLaunched method you may check if user have token. Then you may decide to navigate user to Login or else.
if (youruserdonthavetokenstoredindborlocal)
{
rootFrame.Navigate(typeof(Login));
}
else
{
rootFrame.Navigate(typeof(MainPage));
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.