How does ionic history work and when is a non-root stack created?

后端 未结 2 1868
滥情空心
滥情空心 2020-12-23 16:54

I\'m using ionic v1.0.0 and do not understand the way parallel history managed by $ionicHistory works.

Especially on Android devices, when using the (fo

2条回答
  •  长情又很酷
    2020-12-23 17:23

    As additional information to the previous post.

    A history stack is always linked to an "ion-nav-view" template. So the root history stack is created for the first "ion-nav-view" item.

    If you plan on using different history stacks I would advise to always link the ion-nav-view to a view name: instead of

    In this CodePen you have a RootStack for the tab pages and the other pages (named "tabs", "other", "other1") and then inside the tab pages you have one substack for each tab. The tab pages and other pages run inside the Root ion-nav-view. During my tests I needed to assign a name to the root ion-nav-view and then reference this view name in controller. Otherwise the stack was always recreated when switching between the main pages (Other => Tabs => Other => ..)

    Html for Root Stack:

    
    

    Controller:

     .state('other', {
          url: "/other",
          views: {
            'default': {
              templateUrl:       "templates/other.html",
            }
            },
    .state('tabs', {
          url: "/tab",
          abstract: true,
         views: {
            'default': {
              templateUrl:       "templates/tabs.html",
            }
         }
        })
    

    Inside the tabs template I assigned a new ion-nav-view for the different tab stacks (as it is done in the default ionic tabs template)

    For example for the home-tab (and home stack) the Html looks like this (pages home, facts):

    
    

    Controller:

    .state('tabs.home', {
          url: "/home",
          views: {
            'home-tab': {
              templateUrl: "templates/home.html",
            },
    
          }
        })
        .state('tabs.facts', {
          url: "/facts",
          views: {
            'home-tab': {
              templateUrl: "templates/facts.html",
            },          
          }
        })
    

    I also submitted a bug report for the codepen above. It is wrongly switching back across histories. https://github.com/driftyco/ionic/issues/4086

    I'm not sure of my fix though. Maybe the history feature needs to be redesigned more globally to address issues ..

提交回复
热议问题