Hello community, I have a question about the use of $ionicHistory , which is part of the Navigation extension of the javascript/angular extensions.
I would like to know how to avoid going back when I am in one of the two menus, depending on the role of the user who has entered.
I would like to resolve the following concerns
- You can only hit the back button if the view is not the menu view (either student or teacher)
- In the case of android, there is a back button, whether physical or digital, if it is in the view or template of any of the two menus, then, when you go back, you must exit the application
- Prevent it from saving routes or views in this history, to avoid conflicts in the future.
Your problem can be solved by using the
clearHistory()
service method$ionicHistory
either in your student or teacher view controller you can call that method and this will prevent you from being able to navigate back as that method deletes the history except the current view(that's why you need to do it in the student or teacher view).You can also use the method
nextViewOptions()
and disable the back button like thisBut this must be done from the previous view (the "loading" view) as that applies to the next view to show before transitioning to it.
Lastly, to make your application exit when pressing the back button you have to use the
$ionicPlatform
using serviceonHardwareBackButton
but you are inadvertently running into a problem:The solution that I see for this is to use two back presses instead of one showing a toast with a message with something like "Press again to exit"
You can install the toast with a plugin that you can find at https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin using
Then in the event
platformReady
you set the event(to make sure the plugin has loaded)You can change the timeout to be longer but basically what it does is exit if back is pressed within 2 seconds if it doesn't show the toast again, thus preventing your users from exiting the app by accident.