I am developing a tutorial app using the Cordova Framework7 framework. When I build the APK and test it on my mobile device, I encounter an issue where clicking the back button closes the app. I would like to modify this behavior so that the back button should navigate back to the previous page, unless the current page is the main page (in which case, the app should exit). Could you please help me with the code to implement this functionality?
var app = new Framework7({
id: 'io.framework7.testapp',
el: '#app',
cache: false, /* disable caching */
theme: theme,
pushState : true,
routes: routes,
popup: {
closeOnEscape: true,
},
sheet: {
closeOnEscape: true,
},
popover: {
closeOnEscape: true,
},
actions: {
closeOnEscape: true,
},
vi: {
placementId: 'pltd4o7ibb9rc653x14',
},
methods:
{
onBackKeyDown: function()
{
if (app.views.main.router.url == '/') {
app.dialog.confirm('Are you sure you want to exit?', 'Exit app', function() {
navigator.app.exitApp();
},
function() {
});
} else {
mainView.router.back();
}
}
}
});
document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady() {
document.addEventListener("backbutton", app.methods.onBackKeyDown, false);
}
I had tried this code but its not working. I want to correct my code so that it works