History (back button) not working when using side menus

I recently upgraded my projected to the latest version of Ionic and now I’m experiencing issues with the history functionality.

My project’s main view shows a list of article headlines and uses ion-side-menus for settings. The other views are just plain article pages with ion-content. The problem is that the back button works fine between the normal views but I can’t get it to work to go back to the main view with the side menus. The back button triggers $ionicHistory.goBack(), using viewHistory() shows that Views is null.

When I remove the side menus from the main view the problem is gone. Also when I select an article the slide animation is back too (which was also gone). However this way the settings side menu is gone and that’s not what I want.

I have no idea why using side menus breaks the history, any help?


+1 on this. I have a similar app, back works fine when moving from detail back to master, but $ionicHistory.backView() is always null when moving from one master view (those in the sidemenu) to the other. Help @mhartington


There’s a fix in this stackoverflow post.

Basically the menu-close directive on menu items also resets the history stack.

use this directive instead:

myModule.directive(‘menuCloseKeepHistory’, [’$ionicHistory’, function($ionicHistory) {
return {
restrict: ‘AC’,
link: function($scope, $element) {
$element.bind(‘click’, function() {
var sideMenuCtrl = $element.inheritedData(’$ionSideMenusController’);
if (sideMenuCtrl) {
historyRoot: false,
disableAnimate: true,
expire: 300

Works like a charm.