IONIC 4: Device back button not exiting the app

I’ve been trying to close the app with the device back button but instead of, it goes to a white screen and then go back to the home page.
I tried this:

import { Component } from '@angular/core';
import { Platform } from '@ionic/angular';

  selector: 'app-home',
  templateUrl: '',
  styleUrls: [''],
export class HomePage {

  constructor(private platform: Platform) {}

  subscription: any;

  ionViewDidEnter() {
    this.subscription = this.platform.backButton.subscribe(() => {

  ionViewWillLeave() {

It seems to work to some people, there’s something wrong i’m doing?

Check this issue and try this.

1 Like

I did it!
That was easier than I thought, just added this code in the constructor of

constructor(private platform: Platform) {
    document.addEventListener("backbutton", async () => {