How can moving between tab pages with phone back button

i have tab based ionic app and want to move between tab pages like other pages for example if we are in tab1 and go to tab2 when press back button come back to tab1 instead exit from app how can i implement this in tabs and also when show some page in modal .
please help me tnx.