markhamknight
markhamknight

Reputation: 375

ion-nav-back-button not working in ionic v1

Good day, Im been working on my project for a long time, and I noticed something not working. This is my config.

.state('login', {
    url: '/login',
    templateUrl: 'templates/auth/login.html',
    controller: 'AuthCtrl as auth'
})

.state('signup', {
    url: '/signup',
    templateUrl: 'templates/auth/signup.html',
    controller: 'AuthCtrl as auth'
})

and I have this button on my login.html

<button class="button button-block button-balanced button-small" ng-click="auth.goToSignUp()">Signup</button>

which navigates to the signup page. The problem is that, when im on my signup.html, pressing the ion-nav-back-button does not go back to the login page. I tried searching for some solutions but so far none of which solved my problem. Your help is greatly appreciated

Upvotes: 2

Views: 1949

Answers (1)

HardikDG
HardikDG

Reputation: 6112

You can set the nav-back-button as show in the ionic docs with $state.go

Recommended markup for default settings:

<ion-nav-bar>
  <ion-nav-back-button>
  </ion-nav-back-button>
</ion-nav-bar>

With custom inner markup, and automatically adds a default click action:

<ion-nav-bar>
  <ion-nav-back-button class="button-clear">
    <i class="ion-arrow-left-c"></i> Back
  </ion-nav-back-button>
</ion-nav-bar>

If the above didn't work for you, you can try with $ionicHistory

<ion-nav-bar ng-controller="MyCtrl">
  <ion-nav-back-button class="button-clear"
    ng-click="myGoBack()">
    <i class="ion-arrow-left-c"></i> Back
  </ion-nav-back-button>
</ion-nav-bar>

//In your controller
function MyCtrl($scope, $ionicHistory) {
  $scope.myGoBack = function() {
    $ionicHistory.goBack();
  };

Also, make sure your $ionicHistory is storing the history and you have added that in the controller's dependency list

you can check the current history with $ionicHistory.viewHistory()

Upvotes: 1

Related Questions