Level wise navigation



In my current ionic application i am not using ionicNavView instead i am handling routing with angular's primitive ng-route. I want to use nav but problem is with this i can’t write my custom handling for back button. I have a level wise navigation schema in my application. For e.g. there is a root level (level 0) which is the home screen of the application. From this level user can navigate to various other options (levels) which in turn have their deep levels. I want that if user is in any deep level it always return to root level and if he is at root level then application exist. Is there any way i can control the view history of the nav-view and also the action of back button. I want to exit app when user taps back button 2 times continuously. On first tap it show a message 'Press again to exit'