Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic history stack when using side menu and tabs

I am having some troubles with ionic and its history stack when using side menus and tabs.

I created a plunker example here: http://embed.plnkr.co/XK6seY9mDypTW6GcsCpj/preview

Steps to follow to get to the problem:

  1. Open side menu
  2. Navigate to "Master List"
  3. Choose one of the items
  4. You'll get redirected to the general-data-tab of the detail page

The problem is that there's no back-button displayed in navigation by ionic itself. I created an own back button that calls $ionicGoBack($event) to see whether ionic has the history stack or not. But when clicking this button you'll see that ionic does not navigate back to the master-list, instead you'll stay on the general-data-tab of the detail page.

Can anyone tell me what the problem is? I am aware of tabs having their own history stack, nevertheless the tab should know its ancestor, or am I wrong?

Many thanks in advance for your help!

Best regards

like image 788
baumgarb Avatar asked Feb 21 '15 14:02

baumgarb


People also ask

How do you add tabs to the Ionic app?

Adding Tabs Bar in Ionic Application The tab navigation is created by adding the ion-tabs having ion-tab-bar inside it which creates a tab bar on position defined in the slot property. Each tab button is created using the ion-tab-button with tab property which is the path of tab page resulting navigation.

How do you change tabs in Ionic?

All tabs can be changed by setting the value of tabsLayout on the <ion-tabs> element, or in your app's config. For example, this is useful if you want to show tabs with a title only on Android, but show icons and a title for iOS.


2 Answers

This is due to the fact that the menu-close directive resets the history stack (as explained here).

If you remove "menu-close" from your elements, then you keep the history, but loose some of the expected behaviour.

As a solution, you can develop your own directive (let's say "menu-close-keep-history") to replace the "menu-close" one.

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

This should do the trick.

like image 191
bmathern Avatar answered Oct 04 '22 07:10

bmathern


Well, instead of custom directive, one can use menu-toggle instead of menu-close When you use

menu-toggle

ionic keeps track of your navigation history

like image 25
Niranth Reddy Avatar answered Oct 04 '22 08:10

Niranth Reddy