Ionic framework $state.go('app.home'); is adding back button on page where I want to go (how to remove it)?

前端 未结 6 908
不知归路
不知归路 2021-01-30 12:56

I have app with sidebar menu. I am on second page and I am calling controller function which redirect me to first page using:

$state.go(\'app.home\');


        
相关标签:
6条回答
  • 2021-01-30 13:19

    As long as you have <ion-nav-back-button></ion-nav-back-button> included in <ion-nav-bar> you will see a back button by default on any view using app.

    Removing <ion-nav-back-button> will remove the back button from all of the views using app. You can selectively disable it based on what template your viewing by setting hide-back-button="true" on the <ion-view> of that template.

    So, in your case, removing <ion-nav-back-button class="button-clear"><i class="icon ion-ios7-arrow-back"></i> Back</ion-nav-back-button> from menu.html will hide the back button on all views using app.

    0 讨论(0)
  • 2021-01-30 13:23

    At controller which you want to return HomeCtrl:

    .controller('SavedCtrl', function($scope,...,$ionicHistory) {
      ...
        $ionicHistory.nextViewOptions({
           disableBack: true
        });
    
      $state.go('app.home');
     })
    .controller('HomeCtrl', function($scope,...,$ionicHistory) {
         $ionicHistory.clearHistory();
     })
    
    0 讨论(0)
  • 2021-01-30 13:26

    You can set nextViewOptions before $state.go('Yourstate'). Like In your controller, you can write,

    $ionicHistory.nextViewOptions({
      disableBack: true
    });
    $state.go('app.home');
    

    So for that transition, it will clear the history stack and sets next view as root of the history stack.

    0 讨论(0)
  • 2021-01-30 13:30

    Use $ionicHistory in your controller before calling $state.go('app.home').

    .controller('HomeCtrl', function($scope,...,$ionicHistory) {
      ...
      $ionicHistory.nextViewOptions({
        disableBack: true
      });
    
      $state.go('app.home');
    });
    
    0 讨论(0)
  • 2021-01-30 13:35

    I had this problem too when using Ionic's side menu.

    In some cases when selecting an option from the side menu the resulting page/view was showing a back button in the navbar, which it shouldn't (because selecting a menu option should reset the history).

    The problem was related to using "ng-click" in the menu option, e.g:

    <ion-item menu-close ng-click="showStartPage()" ...>

    with 'showStartPage' being a Controller method which calls $state.go(...).

    Solution was to code it like this:

    <ion-item menu-close href="#/startPage" ...>

    When done like this, Ionic is (apparently) able to properly keep track of the navigation history.

    (I didn't try it out but probably "ui-sref" instead of "href" would work too)

    0 讨论(0)
  • 2021-01-30 13:40
    $ionicNavBarDelegate.showBackButton(false);
    
    0 讨论(0)
提交回复
热议问题