简体   繁体   中英

How To Redirect Hardware Back Button in Ionic 3?

I want to enable the hardware back button in ionic 3 which redirect's the page's and show's the content which we want's to redirect to the page. as i am new to ionic 3 guide me how to redirect buttons from the hardware device?

Something like these?

platform.registerBackButtonAction(()=>{
      // get the current activeNav
      let nav = app.getActiveNavs()[0];
      let active = nav.getActive();

      //crete as many difrent conditions as you need ...
      if(active.instance instanceof Pagename){
      //work u wanna do with dat page name
      }
      if(active.instance instanceof Pagename2){
      //work u wanna do with dat page name
      }

      //Go back
      nav.pop(); 

    },2)  //<- this is priority

You can also check if you can go back with:

if (nav.canGoBack()){
    nav.pop();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM