当我从主页导航到另一个页面时,后退按钮不显示在导航栏上 . 但是,在某些情况下离子显示后退按钮 . 例如导航设置页面表单配置文件页面后退按钮显示正常,移动银行按钮也正常工作 .

目标是当按下移动硬件后退按钮并且导航栏上的显示后退按钮和按下硬件后退按钮时的主页显示确认时,用户必须进入主页 .

我已经在堆栈上搜索了很多问答,但没有找到适当的解决方案 .

这是我的代码,试图 -

.run(function($ionicPlatform, $rootScope, $ionicLoading, $ionicPopup, $ionicHistory, $localStorage, $timeout, $http, $state) {
    $ionicPlatform.ready(function() {
       $ionicPlatform.registerBackButtonAction(function(event) {
            if ($state.current.name=="app.home") {
                $ionicPopup.confirm({
                    title: 'System',
                    template: 'are you sure you want to exit?'
                }).then(function(res) {
                    if (res) {
                        ionic.Platform.exitApp();
                    }
                })
            }
        }, 101);
    });
})

如何强制Ionic在特定页面上显示后退按钮?

.config(function($stateProvider, $urlRouterProvider){
    $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.settings', {
        cache:false,
        url: '/settings',
        views: {
            'menuContent': {
                templateUrl: 'templates/setting/settings.html',
                controller: 'SettingsCtrl'
            }
        }
    })
    .state('app.wfhadd', {
        cache:false,
        url: '/wfh/wfhadd',
        views: {
            'menuContent': {
                templateUrl: 'templates/wfh/addwfh.html',
                controller: 'AddWfhCtrl'
            }
        }
    })
    .state('app.wfhlist', {
        cache:false,
        url: '/wfh/wfhlist',
        views: {
            'menuContent': {
                templateUrl: 'templates/wfh/wfhlist.html',
                controller: 'listWfhCtrl'
            }
        }
    })
    .state('app.login', {
        cache: false,
        url: '/login/:userid/:logpass',
        views: {
            'menuContent': {
                templateUrl: 'templates/login.html',
                controller: 'LoginCtrl',
                params:  {'userid': null, 'logpass': null}
            }
        }
    })
    .state('app.profile', {
        cache: false,
        url: '/settings/profile',
        views: {
            'menuContent': {
                templateUrl: 'templates/setting/profile.html',
                controller: 'ProfileCtrl'
            }
        }
    })
    .state('app.activities', {
        cache: false,
        url: '/activities',
        views: {
            'menuContent': {
                templateUrl: 'templates/activities.html',
                controller: 'ProfileCtrl'
            }
        }
    })
    .state('app.leave', {
        cache: false,
        url: '/leave',
        views: {
            'menuContent': {
                templateUrl: 'templates/leave/leave.html',
            }
        }
    })
    .state('app.leavelist', {
        cache: false,
        url: '/leave/allleaves/:id',
        views: {
            'menuContent': {
                templateUrl: 'templates/leave/leavelist.html',
                controller: 'LeaveCtrl',
                params:  {'leaveid': null}
            }
        }
    })
    .state('app.leavedtls', {
        cache: false,
        url: '/leave/details',
        views: {
            'menuContent': {
                templateUrl: 'templates/leave/leavedtls.html',
                controller: 'LeaveDtlsCtrl'
            }
        }
    })
    .state('app.leaveapply', {
        cache: false,
        url: '/leave/apply',
        views: {
            'menuContent': {
                templateUrl: 'templates/leave/leaveapply.html',
                controller: 'LeaveApplyCtrl'
            }
        }
    })
    .state('app.terms', {
        url: '/settings/terms',
        views: {
            'menuContent': {
                templateUrl: 'templates/policy.html'
            }
        }
    })
    .state('app.about', {
        url: '/settings/about',
        views: {
            'menuContent': {
                templateUrl: 'templates/about.html'
            }
        }
    })
    ;
    $urlRouterProvider.otherwise('/app/home');
})

EDIT 1

现在我已将以下代码放在配置文件控制器和配置文件页面上的后退按钮显示但它不起作用(不返回主页) .

.controller('ProfileCtrl', function($scope,$rootScope, $ionicHistory, $http,$localStorage, $ionicNavBarDelegate){

    $scope.$on('$ionicView.beforeEnter', function (event, viewData) {
        viewData.enableBack = true; 
    });

})