For those trying to sort this on Ionic 2:
http://www.codingandclimbing.co.uk/blog/ionic-2-android-back-button-13
and here is the actual post information:
In app.ts, do the following to return the back button (basically!):
initializeApp() { this.platform.ready().then(() => { this.registerBackButtonListener(); }); } registerBackButtonListener() { document.addEventListener('backbutton', () => { var nav = this.getNav(); if (nav.canGoBack()) { nav.pop(); } else { this.confirmExitApp(nav); } }); } confirmExitApp(nav) { let confirm = Alert.create({ title: 'Confirm Exit', message: 'Really exit app?', buttons: [ { text: 'Cancel', handler: () => { console.log('Disagree clicked'); } }, { text: 'Exit', handler: () => { navigator.app.exitApp(); } } ] }); nav.present(confirm); } getNav() { return this.app.getComponent('nav'); }
Note:
If you made a mistake in the fact that the application is not a property of the navigator :
1) Add the typing folder to the root directory of the application: for example. application / typing
2) Add a file named: pluginshackyhacky.d.ts
3) Add for properties required for TypeScript to compile .:
interface Navigator { app: any; }
4) Add pluginshackyhacky.d.ts to the compilation in tsconfig.json :
"files": [ "app/app.ts", "app/typings/pluginshackyhacky.d.ts", "app/typings/phonegap.d.ts" ]
You can see that I also included the phonegap.d.ts file, which contains many missing properties / variables that allow TypeScript to compile without errors.
Hope this helps anyone who has this problem.
Greetings.