Ionic 2 device back button prevent app exit in tabs

Hi everyone i am new to ionic framework.
I am facing a problem regarding ionic-2 app tabs, I have 3 tabs on my app view one is discovery and others are people and messages … The problem i am having that when i am on message and people tabs and from my phone back button press i just simply exit from my app …
what i want is when i go to my home page which is discovery page and from there if i press back then i exit the app … Any one has any idea about this plz let me know i will be thankful to you …

This happens because tabs is considered a single instance of “page”, and just press one time on this button to exit app. Read the ‘how to’ below:

hi i am using ionic 2 will this be helpful for ionic 2 version as well

Yes, you can use it without more problems. Try it :+1:

1 Like

search for “setRoot” in google and you’ll get what you want. (With postfix ionic 2).

i have tried this but did’t work …

Can you show the code!

sorry dear i searching for solutions and the code was removed …

Ohh ok then it is not a problem… you’ll find a way.

Thats actually pretty simple you have to go into your app.module and add this line of code to the imports.

imports: [
    IonicModule.forRoot(MyApp, {
      navExitApp: false,
    }),
  ],

In that case your Hardware Backbutton can still pop pages and such but won’t close your app!

3 Likes

I have tried it but still the app exits, I am using ionic Pro on android