Remove Login page

Eduardo Gomez 3,416 Reputation points


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


   public App() {

            MainPage = new LoginPage();


   Login = new Command(
                execute: async () => {
                    var isSucess = await Auth.LoginUser(User);
                    if (isSucess) {
                       Page app = Application.Current.MainPage;
                       app = new NavigationPage(new NotebooksPage());
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

    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

    don't add the Login page to the navigation page

             MainPage = new LoginPage();

    After login, add NotebooksPage

             MainPage = new NavigationPage(new NotebooksPage());