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\');
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
.
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();
})
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.
Use $ionicHistory in your controller before calling $state.go('app.home')
.
.controller('HomeCtrl', function($scope,...,$ionicHistory) {
...
$ionicHistory.nextViewOptions({
disableBack: true
});
$state.go('app.home');
});
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)
$ionicNavBarDelegate.showBackButton(false);