You have to do it in code .there is no such function for you to do it.
which means you have to write code in the main cs file.
Shell redirection
Hello! I am using Shell as my main page. When entering the application, if the user is not authenticated, then he goes to the page that he should not see. Is there some way to redirect the user to the login page if they are not authenticated?
2 answers
Sort by: Most helpful
-
mc 4,836 Reputation points
2021-01-31T01:16:19.487+00:00 -
Leon Lu (Shanghai Wicresoft Co,.Ltd.) 77,256 Reputation points Microsoft Vendor
2021-02-01T02:48:10.03+00:00 Hello,
Welcome to our Microsoft Q&A platform!
I am using Shell as my main page. When entering the application, if the user is not authenticated, then he goes to the page that he should not see. Is there some way > to redirect the user to the login page if they are not authenticated?
When app starts, then check if user is logged. If so then goto MainPage, else go to LoginPage. Am I right?
Her is achieve code about it.
- Replace order of items in AppShell.xaml <!-- Your Pages -->
<TabBar Route="main">
<Tab Title="Browse" Icon="tab_feed.png">
<ShellContent ContentTemplate="{DataTemplate local:ItemsPage}" />
</Tab>
<Tab Title="About" Icon="tab_about.png">
<ShellContent ContentTemplate="{DataTemplate local:AboutPage}" />
</Tab>
</TabBar> <ShellItem Route="login">
<ShellContent ContentTemplate="{DataTemplate local:LoginPage}" />
</ShellItem> - Then edit App.xaml.cs to check login state public App()
{
InitializeComponent();
}DependencyService.Register<MockDataStore>(); var isLoogged = Xamarin.Essentials.SecureStorage.GetAsync("isLogged").Result; if (isLoogged == "1") { MainPage = new AppShell(); } else { MainPage = new LoginPage(); }
Then edit in
LoginPage.xaml.cs
protected async void OnClicked(object source, EventArgs args) { await Xamarin.Essentials.SecureStorage.SetAsync("isLogged", "1"); Application.Current.MainPage = new AppShell(); await Shell.Current.GoToAsync("//main"); }
If you need more details, you can refer to this answer:https://stackoverflow.com/a/57348505/10627299
Best Regards,
Leon Lu
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
- Replace order of items in AppShell.xaml <!-- Your Pages -->