Disable hardware back button after setRoot to next page


#1

Hi,
I have a problem on my ionic 2 project, i have a sequence of pages like this:

Splash screen> Welcome Page> (setRoot) Home Page

as we know the page that ‘setRoot’ does not have a back button on the UI, but why when I press the back button on the hardware, the page returns to ‘WelcomePage’. How about when ‘HomePage’ can not return to ‘WelcomePage’?

Thank you


#2

May be something like below mentioned code would work for you. You just need to put condition for which page currently looking at.

platform.ready().then(() => {
          // Okay, so the platform is ready and our plugins are available.
          // Here you can do any higher level native things you might need

          platform.registerBackButtonAction(() => {
            if(this.menu.isOpen()){
               this.menu.close()
            } 
            else if(this.nav.canGoBack()){
              this.nav.pop();
            }else{
              //don't do anything
            }
          });
        });

#3

thank you for replying, but I found my own solution by updating the ionic project to the latest version


#4

the other solution was to set the RootPage by login, and to come back to default if user was not logged in. (that’s what i do in my app).

Have fun with ionic,