如何在framework7中检测android的后退按钮

Aak*_*kar 2 html-framework-7

我最近正在使用framework7构建一个应用程序。我的应用程序由一个 html 文件组成,其中包含所有视图。为了在视图之间导航,页面底部有一个后退按钮。

对于后退按钮,我正在使用代码

var myView = app.view.current;

myView.router.back();
Run Code Online (Sandbox Code Playgroud)

如果我按下 Android 设备上的后退按钮,应用程序将关闭

如何使用 Android 手机的后退按钮进入主页。

我已经使用了PushState:true但它对我不起作用。

下面是我的 app.js 文件

    // Dom7
    var $ = Dom7;

    // Theme
    var theme = 'auto';
    if (document.location.search.indexOf('theme=') >= 0) {
    theme = document.location.search.split('theme=')[1].split('&')[0];
    }

    // Init App
    var app = new Framework7({
    id: 'io.framework7.testapp',
    root: '#app',
    theme: theme,
    on:{
    pageInit : function(page){
       console.log("page init function called aakash");
       document.addEventListener("backbutton", app.methods.onBackKeyDown, 
    false);
    }
     },
    pushState:true,
    data: function () {
    return {
      user: {
        firstName: 'John',
        lastName: 'Doe',
      },
    };
    },
   methods: {
     helloWorld: function () {
      console.log('dfvdfv')
      app.dialog.alert('Hello World!');
     },
     onDeviceReady: function() {


     },

    onBackKeyDown: function() {

       console.log("back button pressed");


      }
   },
    routes: routes,
    vi: {
      placementId: 'pltd4o7ibb9rc653x14',
     },

});
Run Code Online (Sandbox Code Playgroud)

Aak*_*kar 5

好吧,我有一个解决方案!这对我有用

var app = new Framework7({
  initOnDeviceReady:true,
  view:{
     pushState:true,

    } 
});
Run Code Online (Sandbox Code Playgroud)