Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 71531

Ionic 4 - Hardware Back Button Return to Root (Home)

$
0
0

@plaidfox wrote:

I’m currently trying to setup a custom hardware back button function for my app through Android Devices. My current setup includes a Home Page -> Page 1 -> Page 2 -> Page 3. What I’d like to have happen is when the user is currently on Page 3 and hits the hardware back button on an Android device, the user is then sent back to the home page every time.

I have the following code setup in my app.component.ts, but I’m not sure what to put in the (???) spot to force the hardware back button to send the user to the homepage:

this.platform.backButton.subscribe(() => {
if (this.router.url === '/page-3') {
   ???
  //magic code that sends the user back to the home page
} else if (this.routerOutlet && this.routerOutlet.canGoBack()) {
this.routerOutlet.pop();
}

Anyone have any thoughts into what I should be looking into? I’ve looked into Navigation Controllers, Routers, Router Outlets, Guards but haven’t found a definitive answer to my problem. Any help would be greatly appreciated. Thanks.

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 71531

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>