How to set up sidemenu with tabs in Ionic?

前端 未结 1 326
天命终不由人
天命终不由人 2021-01-12 16:21

In my opinion having a sidemenu, for things like settings and about pages, combined with tabs for the main app is a pretty essential and standard app interface. Things like

1条回答
  •  余生分开走
    2021-01-12 17:14

    I think your routing is a bit off - your child states for the tabs aren't fully declared. You've declared them like this

    .state('tab.tab1', {
    

    ...and you've never declared the parent tab state. So they are left 'hanging' until the parent state is declared. ui-router will just ignore them until this happens.

    Try this

    config(function($stateProvider, $urlRouterProvider) {
      $stateProvider
    
      .state('app', {
        url: "/app",
        abstract: true,
        templateUrl: "templates/menu.html",
        controller: 'AppCtrl'
      })
    
      .state('app.tabs', {
        url: "/tabs",
        views: {
          'menuContent': {
            templateUrl: "templates/tabs.html"
          }
        }
      })
    
    .state('app.tabs.tab1', {
          url: '/tab1',
          views: {
            'tab-tab1': {
              templateUrl: 'templates/tab-tab1.html',
              controller: 'tab1Ctrl'
            }
          }
        })
    
    .state('app.tabs.tab2', {
          url: '/tab2',
          views: {
            'tab-tab2': {
              templateUrl: 'templates/tab-tab2.html',
              controller: 'tab2Ctrl'
            }
          }
        })
    
    .state('app.tabs.extras', {
        url: '/extras',
        views: {
          'tab-extras': {
            templateUrl: 'templates/tab-extras.html',
            controller: 'AccountCtrl'
          }
        }
      })
    
        .state('app.about', {
          url: "/about",
          views: {
            'menuContent': {
              templateUrl: "templates/about.html",
              controller: 'aboutCtrl'
            }
          }
      });
      // if none of the above states are matched, use this as the fallback
      $urlRouterProvider.otherwise('/app/tabs');
    });
    

    And better / clearer to use ui-sref rather than href in your tabs template - easier to see what state something maps to

      
    
      
        
      
    
      
        
      
    
      
        
      
    
    
    

    Not tested it but I think that should fix it! Any errors in the console BTW?

    0 讨论(0)
提交回复
热议问题