Android back button causes side-menu app to exit

I am new to Ionic and liking it so far. I’m having an issue with Android and navigation. This maybe due to my ignorance but I am a little confused how everything should fit together. I’m using a side-menu with Angular’s ngRoute service. That seems to work in the browser when using back/forward buttons. When I deploy it to the device, the back button causes the app to exit. I poked around the forum a little but still uncertain what is the expected behavior should be. I’d like to be able to use the back-button to bring the user back to the previous view in side-menu content (where the templates are being swapped out based on route).

Questions:

  1. What is the expected behavior of back button on Android device in a pure side-menu app without routing?
  2. Should I be able to use ion-nav-view to host templates inside side-menu-content withouth ion-nav-bar and maintain history?
  3. But still, is it Ionic’s limitation not handling Android’s back button? Should I be looking at Cordova’s API to handle it??

Thank you.

Let’s clarify “using a side-menu with Angular’s ngRoute service”

Are you actually using ngRoute? If so, you really shouldn’t anymore. Ionic switch to UI-Router several months ago. Checkout the “Getting Startedionic start myApp sidemenu for a side menu sample using ui-router.

  1. I believe the back button should walk you backward through the navigation stack just like the back button on the desktop
  2. & 3. It’s kind of hard to answer this without really understanding what you are doing? Do you have no “main content” outside the sidemenu? Setting up a CodePen sample might help us understand.

Thank you.

I tried using ion-nav-view before w/o ion-nav-bar and that didn’t seem to work. That led me to think ion-nav-view requires ion-nav-bar, which I didn’t want in the app so I went with ngRouter first. But that doesn’t handle device back button correctly.

I then found that example last night and tried it and it worked on the device. It also seems I can “not” have the nav buttons in the example. I will try to fit my templates, views, etc into the same pattern.

So I guess I am confused on how “ion-nav-view”, “ion-nav-bar”, and “$routeProvider” all work. I thought “ion-nav-view” and “$routeProvider” are enough to register routes, navigation history, and template swapping. “$ion-nav-bar” simply adds UI elements to allow navigation. But that doesn’t seem to be the case, can you clarify?

Thank you.

Got this problem also and I want to share the issue or the solution.

    <ion-item nav-clear menu-close ui-sref="app.home">
      Home
    </ion-item>

nav-clear attribute, it clears the navigation history, that is why the application close on mobile back button after a side menu link.

I have the same problem, and try the solution @leiron but still have the same problem.
How can I fix this problem?