Hwo can i add a home button with back button

I want to add a home button on my pages which are deep linked into page after page , if my user want to go home direct what should i do to add home button on my nav-bar

1 Like

For an example:

  <ion-nav-buttons side="left">
      <a href="/#/home" menu-toggle="left" class="button button-icon icon ion-navicon"></a>
  </ion-nav-buttons>

You can add it using <ion-nav-buttons>. For example:

<ion-nav-buttons side="right">
    <button ng-show="$root.showHome" class="button button-icon button-clear ion-home"></button>
</ion-nav-buttons>  

And then if you don’t want it displayed when there is no back button you could put this in the Menu controller (or a variation of this)

// If the back button is enabled show the home button
$scope.$on('$ionicView.beforeEnter', function (e, data) {
    if (data.enableBack) {
        $scope.$root.showHome = true;
    } else {
        $scope.$root.showHome = false;
    }
});
1 Like

Thanks for help,
There is one more problem after that when it reaches to home the back button is enabled as well.

Define a function that clears the history stack before navigating home:

$ionicHistory.nextViewOptions({
    historyRoot: true
});
$state.go('home');
2 Likes