Unexpected backbutton icon

I create an Ionic project with sidemenu template. Run it, and navigate from homepage(Lists) to another page(Browser), but when I click hardware backbutton to go back to homepage,the header-bar’s left button is backbutton icon instead the menu icon. why? Thx a lot to help me

The menu-close directive on the menu item will reset the view’s history stack. When you use the hardware back button to get back to the homepage there is a back view because the history isn’t reset.

I’m not sure if this is something Ionic is going to handle in the future, but you can override the action of the back button:

// Override the android back button
$ionicPlatform.registerBackButtonAction(function () {
    if ($state.current.name == "browser") {
        // clear history before navigating
        $ionicHistory.nextViewOptions({
            disableAnimate: true,
            historyRoot: true
        });
        navigator.app.backHistory();
        return;
    } else {
        navigator.app.backHistory();
    }
}, 100);
1 Like

Thanks so much, I will try it at company on monday. I hava already overrided the action of the hardware back button to achieve the purpose double click exitApp. I think Ionic should do more about it ,navigation of the first-level menu should not appear the backbutton icon,but the normal menu icon. thank you again

1 Like

@brandyshea Wow! Nice solution I was looking for.

1 Like

Wow!!!Exciting!!It works perfect.Most sincere thanks.By the way ,how can I get the usage like nextViewOptions or disableAnimate and so on. I just looking for all around but nothing can get

1 Like

Sorry,I ought not to ask all the way,but to do something by myself.I have found the usage on the docs.Thank you

1 Like

Just to add on to my previous post: I added a property to my states called “menuState” like this:

.state('contact', {
    menuState: true,
    url: '/contact',
    templateUrl: 'templates/contact.html'
})

Then when I override the back button I can check for this property:

if ($state.current.menuState == true) {
    $ionicHistory.nextViewOptions({
        disableAnimate: true,
        historyRoot: true
    });
    navigator.app.backHistory();
}

This makes it easier to add more items to the menu without hard coding the state each time it’s added.

1 Like

Really really really thankfull to you! I have learned so much from you ~

1 Like