Ionic 2 device back button prevent app exit in tabs


#1

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 …


#2

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:


#3

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


#4

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


#5

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


#6

i have tried this but did’t work …


#7

Can you show the code!


#8

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


#9

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


#10

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!


#11

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