question

Angelru-4290 avatar image
0 Votes"
Angelru-4290 asked JessieZhang-2116 commented

Shell routes

I have:

 <ShellItem Route="MainPage" Shell.FlyoutBehavior="Disabled" FlyoutItemIsVisible="False">
            <ShellContent ContentTemplate="{DataTemplate local:MainPage}" />
  </ShellItem>
    
   <FlyoutItem Route="Main" FlyoutDisplayOptions="AsMultipleItems" IsTabStop="False">
                ....
  </FlyoutItem>

AppShell:

     Routing.RegisterRoute("Register", typeof(RegisterPage));
     Routing.RegisterRoute("Login", typeof(LoginPage));


MainPageViewModel (local:MainPage):

    await Shell.Current.GoToAsync("Login");
    await Shell.Current.GoToAsync("Register");



Logout in FlyoutItem Route="Main":

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


the problem is that when I login and then close it, the page displayed is the LoginPage and not MainPage






dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

JessieZhang-2116 avatar image
0 Votes"
JessieZhang-2116 answered JessieZhang-2116 commented

Hello,


Welcome to our Microsoft Q&A platform!

Normally, LoginPage is to only show when user is not logged to app.

You can refer to the following code:

AppShell.xaml

 <?xml version="1.0" encoding="UTF-8"?>
 <Shell xmlns="http://xamarin.com/schemas/2014/forms" 
        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
        xmlns:d="http://xamarin.com/schemas/2014/forms/design"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:vm="clr-namespace:ShellLoginSample.ViewModels"
        mc:Ignorable="d"
        FlyoutBehavior="Disabled"
        xmlns:local="clr-namespace:ShellLoginSample.Views"
        xmlns:app="clr-namespace:ShellLoginSample"
        Title="ShellLoginSample"
        x:Class="ShellLoginSample.AppShell">
    
     <Shell.BindingContext>
         <vm:AppViewModel/>
     </Shell.BindingContext>
    
     <ShellItem Route="login">
         <ShellContent ContentTemplate="{DataTemplate local:LoginPage}"/>
     </ShellItem>
        
     <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>
         <Tab Title="Admin" IsVisible="{Binding IsAdmin}">
             <ShellContent
                 ContentTemplate="{DataTemplate local:AdminPage}"/>
         </Tab>
     </TabBar>
 </Shell>

AppShell.xaml.cs

 public partial class AppShell : Xamarin.Forms.Shell
 {
     public AppShell()
     {
         InitializeComponent();

         Routing.RegisterRoute("registration", typeof(RegistrationModal));
     }
 }

Page RegistrationModal.xaml.cs

 public partial class RegistrationModal : ContentPage
 {
     public RegistrationModal()
     {
         InitializeComponent();
     }

     private async void TapGestureRecognizer_Tapped(object sender, EventArgs e)
     {
         await Shell.Current.GoToAsync("//login");
     }

     private async void Button_Clicked(object sender, EventArgs e)
     {
         await Shell.Current.GoToAsync("//login");
     }
 }

Refer:https://github.com/davidortinau/ShellLoginSample

And there is also a similar thread about this, you can check:https://stackoverflow.com/questions/54586621/whats-the-correct-way-to-implement-login-page-in-xamarin-shell



Best Regards,


Jessie Zhang


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.


· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

If you check my example you can see that my MainPage has the login and register, if I remove the MainPage and pogo just the LoginPage it works as expected ...

0 Votes 0 ·

Have you resolved your problem, right? Congrats. Thanks for your support for xamarin.

0 Votes 0 ·