I've creeated an Apache Cordova project for a single page application. On the start page there is a list of items. When I click on a item I navigate to the details page with
window.navigate("#/details/" + id);
Angular.js displays the details template but when I use the hardware backbutton on a windows phone it suspends the application instead ov navigating back. So I tried to hook up to the backbutton event
function onDeviceReady() {
// Handle the Cordova pause and resume events
document.addEventListener('pause', onPause.bind(this), false);
document.addEventListener('resume', onResume.bind(this), false);
document.addEventListener("backbutton", onBackButton, false);
}
but this event isn't even fired when I click the back button. I also use WinJS and tried WinJS.Application.onbackclick but even this doesn't work.
So how can I handle the back button on Windows Phone universal?
This looks like a bug in the Windows Phone Runtime target for Cordova. In Silverlight the CordovaPage.xaml.cs file hooks up the Windows Phone BackButton event handling and forwards it to Cordova's backButton event.
This doesn't happen in the Runtime version, so you'll have to add your own platform specific handling either by handling WinJS's onbackclick event or the Windows.Phone.UI.Input.HardwareButtons.BackPressed event.