$ionicPlatform.registerBackButtonAction(function (event) {
event.preventDefault(); // Back button will DO NOTHING.
//$ionicHistory.goBack();
//$state.go('menu.home'); //go to specific url
//alert("Going back!!!");
}, 100);
but I am unable to navigate any where , the alert works so I tried more,
$ionicHistory.goBack();
$state.go('menu.home');
both of em don’t work to go to previous page I have added
$ionicPlatform.registerBackButtonAction(function (event) in .run(function($ionicPlatform)
@thaker …
Yes and I did it by using window.history.back();
It works just fine in android…
Now I am unable to close the app when back button is pressed @ home page.
state of my homepage:
$stateProvider
@anicacute09 solution is also right,
My logic of back button is here in .run function in app.js
$ionicPlatform.registerBackButtonAction(function (e) {
if ($rootScope.backButtonPressedOnceToExit) {
ionic.Platform.exitApp();
} else if ($ionicHistory.backView()) {
$ionicHistory.goBack();
} else {
ionicToast.show("Press back button again to exit", 'middle', false, 3000);
$rootScope.backButtonPressedOnceToExit = true;
}
e.preventDefault();
return false;
}, 101);
when user press back button it will go back till it haves back view, after coming on first page, toast will come that Press back button again to exit after user click back button user will exit from app.
I was able to check the same in android monitor , every time I hit back button it says,
D/SystemWebChromeClient: file:///android_asset/www/js/app.js: Line 42 : Uncaught ReferenceError: $state is not defined
07-05 13:01:54.191 7197-7197/io.ionic.starter I/chromium: [INFO:CONSOLE(42)] "Uncaught ReferenceError: $state is not defined", source: file:///android_asset/www/js/app.js
I have made no changes in this ionic1 app so far and I am a new beee to ionic framework
I did the same changes and it worked moreover it is also supports the else case with window.history.back and @ home page it gives me the alert and exit if pressed yes… Thank You
People should try this all they need to do is inject the $state, $ionicPopup