Remove Login page

Eduardo Gomez 3,416 Reputation points
2021-06-21T08:59:13.27+00:00

Hello

I have this scenario

LoginPage => NotebooksPage => NotesPage

When the user logs in, I need to prevent him to go back to the login page

I already removed the back button on the navigation bar, on the notebooks page

But Android has a back button, so if I press it, I go back to the login page

This is my Setup

app.cs

   public App() {
            SyncfusionLicenseProvider.RegisterLicense(KEY);
            InitializeComponent(); 

            MainPage = new LoginPage();
        }

LoginCommand

   Login = new Command(
                execute: async () => {
                    UserDialogs.Instance.ShowLoading("Wait...");
                    var isSucess = await Auth.LoginUser(User);
                    if (isSucess) {
                        UserDialogs.Instance.HideLoading();
                       Page app = Application.Current.MainPage;
                       app = new NavigationPage(new NotebooksPage());
                    }
                    UserDialogs.Instance.HideLoading();
                },
Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,292 questions
0 comments No comments
{count} votes

Accepted answer
  1. JarvanZhang 23,936 Reputation points
    2021-06-22T01:52:12.11+00:00

    Hello @Eduardo Gomez ,​

    Welcome to our Microsoft Q&A platform!

    Please don't use the following way to set the MainPage. The Application.Current.MainPage is the code to get and set the root page. In the first line, the Application.Current.MainPage is on the right side which means to get the current MainPage. The app actually is the login page, you could add a breakpoint to check that.

       Page app = Application.Current.MainPage; // app is login page  
       app = new NavigationPage(new NotebooksPage());  
    

    To set the root page, please place the code on the left of the equal sign.

       Application.Current.MainPage = new NavigationPage(new NotebooksPage());  
    

    Best Regards,

    Jarvan 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.


1 additional answer

Sort by: Most helpful
  1. Alessandro Caliaro 4,181 Reputation points
    2021-06-21T09:44:04.103+00:00

    don't add the Login page to the navigation page

             MainPage = new LoginPage();
    

    After login, add NotebooksPage

             MainPage = new NavigationPage(new NotebooksPage());