Removing the back button on view change

Hey guys,

trying to get rid of the back button when going from my log in page to the main view… any idea how I can do that from the controller?
I have tried all the solutions proposed on the forum and some were deprecated and others like $ionicHistory.clearCache(); just won’t work…

Thanks for your help in advance!

1 Like

Set <nav-page hide-back-button=“true”> to hide it for a page (or pages).

how do I set that in the controller thought?

No you write that in the HTML

You can use $ionicNavBarDelegate.showBackButton(false)$ionicNavBarDelegate/

1 Like

Hi thanks that works! :smile:

How do I get the side menu button appear again? I tried:
but it opens it and that’s not what I want
Also I am not sure why but I lost the back button on all states now…

I did that in my state to get rid of the back button and keep the menu button
cache: false,
however knowing the js to show the button would be awesome :slight_smile:

So I’m guessing somethings wrong in the markup for the project.

This is how a sidemenu project should be set up

that’s the one I used to start building the app.
Basically here is what I do:

// Home when logged in
  .state('app.home', {
    cache: false,
    url: "/home",
    views: {
      'menuContent': {
        templateUrl: "templates/home.html",
        controller: 'HomeCtrl'

 * Home Controller
.controller('HomeCtrl', function($scope, $state, $ionicNavBarDelegate, $ionicSideMenuDelegate) {
  // remove back button show the side menu icon after login - Doesn't work how it is supposed to

I think what you want to do is set the home state to the root of the navigation stack. This will make it so you can’t go back to the login page but the menu icon will show:

    historyRoot: true

I put this in a function in a service and call it every time I want to navigate to the home page.


do you mind sharing your service? It sounds like a lot of code for something that should be really simple or is not?

That was basically all of the code. I just place it in a service so I can call it from any controller. Here’s my service (without all unrelated code):

app.service('sharedFunctions', function($state, $ionicHistory) {
    return {
        goHome: goHome

    function goHome() {
            disableAnimate: true,
            historyRoot: true

Then in my controller:

app.controller('MainCtrl', function($scope, sharedFunctions) {
    $scope.sharedFunctions = sharedFunctions;

And in my html I have a button that calls it:

<button class="button button-clear" nav-direction="none" ng-click="sharedFunctions.goHome()"><i class="icon ion-home"></i></button>

When you go from the login state to the home state it keeps the login as a back view, so even if you disable the back button it won’t show the menu because the back view exists (if you have enable-menu-with-back-views=“false” on your sidemenu). The menu-close directive resets the navigation stack when placed on an item in your sidemenu, so that is all I am doing when going to the home state of my sidemenu. I’m not sure if there is a better way to do this, but it works for me.


Quick one, when you do that does that reset your $scope variables that might have been previously loaded?

No, it doesn’t. :smile:

Yeap, just realized I was loading a view and datas after so it would not show until page reload… haha using resolve should help

Thanks for your help :slight_smile:

1 Like