Is there a way for using menu-close without resetting the view's history stack?


Hi, I’m using a side menu for going to a view that not uses a side menu. So I can’t use the menu-close attribute in the button that links the view because it deletes the history stack and I can’t come back.

The problem is that if I remove the menu-close attribute I can go back to the menu view with an ion-nav-back-button, but when I come back the menu is open.

What could I do for coming back and find the menu closed?

Thanks, for your help :slight_smile:

Ion-item href not showing back button on nav-bar when clicked

The reason why the history stack is reset when clicked is that menu-close directive calls $ionicHistory.nextViewOptions to do that.
Check it.
historyRoot: true will wipe up the stack.

In my case, I don’t want to consider a “directive linkage order”, I made my clone directive of menu-close and changed to historyRoot: false.


Hi @theGivingTree, thanks for your answer. I Tried to clone the directive as you said but it is not working, could you tell me what am I doing wrong?

First I created the file www/servicios/directivas.js with this content:

app.directive('menuClose', ['$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
          console.log("MENÚ CERRADO")

After this, I included this file in the www/index.html

<script src="servicios/directivas.js"></script>

and used the cloned directive in the menu template

<a class="item item-icon-left" menu-close ui-sref="verCarrito">
  <i class="icon ion-ios-cart"></i>

The problem is that even with historyRoot: false I can’t get back.

I checked with a console.log that the cloned directive is being used, and checked the history with console.log($ionicHistory.backView()) but it is null when I use the menu link.

Hope you can help me, Thanks :slight_smile:


I think ionic’s menuClose and your menuClose conflicts. Angular will execute both of menuCloses. In your case, ionic’s menuClose seems to execute lastly.

Simply name your own menuClose to something else like myMenuClose and do not use menuClose.


Thanks!! you are right, I changed the name and worked!!.

I thought that the directive was overridden, not that both were running at the same time


Remove menu-close and add menu-toggle=“left” in ion-item


Simple solution. Worked for me.
Thanks @ronel011