2015-10-16 64 views
0

我的問題是,當我瀏覽從狀態user.tab1狀態,後退按鈕不會顯示在導航欄,我怎麼能解決這個問題,我是新來的離子型ion-nav-back-button沒有出現在我的項目結構中?

我有這個規定在我的項目:

var app = angular.module('myApp', ['ionic']); 
    app 
    .config(function ($stateProvider, $urlRouterProvider) { 
     $stateProvider 
      .state('home', { 
       url: '/home', 
       templateUrl: './templates/test/home.html' 
      }) 
      .state('user', { 
       url: '/user', 
       templateUrl: './templates/test/user.html' 
      }) 
      .state('user.tab1', { 
       url: '/tab1', 
       views: { 
        'tab1': { 
         templateUrl: './templates/test/tab1.html' 
        } 
       } 
      }) 
      .state('user.subtab1', { 
       url: '/subtab1', 
       views: { 
        'tab1': { 
         templateUrl: './templates/test/sub-tab1.html' 
        } 
       } 
      }) 
      .state('user.tab2', { 
       url: '/tab2', 
       views: { 
        'tab2': { 
         templateUrl: './templates/test/tab2.html' 
        } 
       } 
      }); 
     $urlRouterProvider.otherwise("/home"); 
    }); 

,這些都是模板:

的index.html

<body ng-app="myApp"> 
    <ion-nav-bar class="bar bar-calm"> 
     <ion-nav-back-button> 
     </ion-nav-back-button> 
    </ion-nav-bar> 
    <ion-nav-view> 
    </ion-nav-view> 
</body> 

home.html做爲

<ion-view view-title="Home"> 
    <ion-content> 
     <a ui-sref="user.tab1">user.tab1</a> 
    </ion-content> 
</ion-view> 

user.html

<ion-view view-title="User"> 
    <ion-tabs> 
     <ion-tab title="tab1" href="#/user/tab1"> 
      <ion-nav-view name="tab1"></ion-nav-view> 
     </ion-tab> 

     <ion-tab title="tab2" href="#/user/tab2"> 
      <ion-nav-view name="tab2"></ion-nav-view> 
     </ion-tab> 
    </ion-tabs> 
</ion-view> 

tab1.html

<ion-view view-title="tab1"> 
    <ion-content> 
     tab1 
     <br /> 
     <a ui-sref="user.subtab1">user.subtab1</a> 
    </ion-content> 
</ion-view> 

tab2.html

<ion-view view-title="tab2"> 
    <ion-content> 
     tab2 
    </ion-content> 
</ion-view> 

子tab1.html

<ion-view view-title="sub-tab1"> 
    <ion-content> 
     sub-tab1 
    </ion-content> 
</ion-view> 

UPDATE

我改變美國對這些,但是當我再次從家鄉導航給用戶,後退按鈕不會出現:

$stateProvider 
     .state('main', { 
      url: '/main', 
      abstract: true, 
      templateUrl: './templates/test/main.html' 
     }) 
     .state('home', { 
      url: '/home', 
      parent: 'main', 
      views: { 
       'home-view': { 
        templateUrl: './templates/test/home.html' 
       } 
      } 
     }) 
     .state('user', { 
      url: '/user', 
      parent: 'main', 
      views: { 
       'user-view': { 
        templateUrl: './templates/test/user.html' 
       } 
      } 
     }) 

main.html中

<ion-nav-view name="home-view"> 
</ion-nav-view> 

<ion-nav-view name="user-view"> 
</ion-nav-view> 
+0

在您的用戶狀態下:將'parent:'main''更改爲'parent:'home'' –

+0

不起作用! @AndreKreienbring –

回答

1

這裏的問題是,你的用戶狀態是不是你的家鄉的孩子。 在您的配置中,只有tab2 &選項卡2狀態是用戶狀態的子項。

因此後退按鈕不會出現。

實施例:

.state('home', { 
    url: '/home', 
    templateUrl: 'templates//test/home.html' 
    }) 

    .state('home.user', {... 

並熟悉的抽象狀態的作爲導航的根的概念。抽象狀態是無法導航到的狀態。如this question中所述。

+0

你能幫我解決這個問題嗎? –

+0

看看這個[codepen](http://codepen.io/TimothyKrell/pen/bnukj)。它解釋的東西... –

+0

是的,但我不明白,你能修改我的錯誤在上面的模板和腳本? –