离子框架$ state.go('app.home'); 是在我要去的页面上添加后退按钮(如何删除它)?

red*_*rom 50 javascript angularjs angular-ui-router ionic-framework

我有侧边栏菜单的应用程序.我在第二页,我正在调用控制器功能,它将我重定向到第一页使用:

$state.go('app.home');
Run Code Online (Sandbox Code Playgroud)

问题是在这个页面上现在显示后退按钮下一个侧边栏菜单图标,见下图:

在此输入图像描述

有人可以告诉我如何拒绝将按钮添加到已分配侧栏菜单的页面中吗?

谢谢你的帮助.

app.js与路由器配置如下:

angular.module('Test', ['ionic', 'config', 'Test', 'LocalStorageModule'])

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)
    if(window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
    }
    if(window.StatusBar) {
      // org.apache.cordova.statusbar required
      StatusBar.styleDefault();
    }
  });
})

.config(function($stateProvider, $urlRouterProvider, localStorageServiceProvider) {
   localStorageServiceProvider
     .setPrefix('max_relax');
   $stateProvider

    .state('app', {
      url: '/app',
      abstract: true,
      templateUrl: 'templates/menu.html',
      controller: 'AppCtrl'
    })

    .state('app.home', {
      url: '/home',
      views: {
        'menuContent' :{
          templateUrl: 'templates/home.html',
          controller: 'HomeCtrl'
        }
      }
    })

    .state('app.saved', {
      url: '/saved',
      views: {
        'menuContent' :{
          templateUrl: 'templates/saved.html',
          controller: 'SavedCtrl'
        }
      }
    })
    .state('app.settings', {
      url: '/settings',
      views: {
        'menuContent' :{
          templateUrl: 'templates/settings.html',
          controller: 'SettingsCtrl'
        }
      }
    });
  // if none of the above states are matched, use this as the fallback
  $urlRouterProvider.otherwise('/app/home');
});
Run Code Online (Sandbox Code Playgroud)

编辑:

添加了菜单模板:

<ion-side-menus>

  <ion-pane ion-side-menu-content>
    <ion-nav-bar class="bar-stable">
      <ion-nav-back-button class="button-clear"><i class="icon ion-ios7-arrow-back"></i> Back</ion-nav-back-button>
    </ion-nav-bar>
    <ion-nav-view name="menuContent" animation="slide-left-right"></ion-nav-view>
  </ion-pane>

  <ion-side-menu side="left">
    <header class="bar bar-header bar-stable">
      <h1 class="title">Menu</h1>
    </header>
    <ion-content class="has-header">
      <ion-list>
        <ion-item nav-clear menu-close href="#/app/home">
          Home
        </ion-item>
        <ion-item nav-clear menu-close href="#/app/saved">
          Saved
        </ion-item>
        <ion-item nav-clear menu-close href="#/app/settings">
          Settings
        </ion-item>

      </ion-list>
    </ion-content>
  </ion-side-menu>
</ion-side-menus>
Run Code Online (Sandbox Code Playgroud)

Bel*_*llu 146

$ionicHistory在呼叫之前在控制器中使用$state.go('app.home').

.controller('HomeCtrl', function($scope,...,$ionicHistory) {
  ...
  $ionicHistory.nextViewOptions({
    disableBack: true
  });

  $state.go('app.home');
});
Run Code Online (Sandbox Code Playgroud)

  • 当使用$ state.go时,我们可以重置状态历史记录,因此框架不会添加后退按钮.从登录视图进入主视图时,这是理想的:$ ionicHistory.nextViewOptions({historyRoot:true})$ state.go("app.home"); (8认同)
  • $ ionicViewService现已弃用,我们必须使用$ ionicHistory.其他一切都是一样的. (6认同)

Shr*_*oni 26

您可以在$ state.go('Yourstate')之前设置nextViewOptions.就像在你的控制器里,你可以写,

$ionicHistory.nextViewOptions({
  disableBack: true
});
$state.go('app.home');
Run Code Online (Sandbox Code Playgroud)

因此,对于该转换,它将清除历史堆栈并将下一个视图设置为历史堆栈的根.