Back Button not working in the app

I have added a back button in my app on the home page that will allow my app to exit. Somehow when I want to go back from another page to home page then also the app destroys and I return to my phone.

import { Component, OnInit, OnDestroy, AfterViewInit } from '@angular/core';
import { Platform } from '@ionic/angular';

  selector: 'app-home',
  templateUrl: '',
  styleUrls: [''],
export class HomePage implements OnInit, OnDestroy, AfterViewInit {

  constructor( private platform: Platform) {

  ngOnInit() {

  ngAfterViewInit() {
    this.backButtonSubscription = this.platform.backButton.subscribe(() => {

  ngOnDestroy() {

What should I do so that my application only exits from the home page and not from all the pages.

Are you sure ngOnDestroy() is called when you navigate from Home to another page ?

I am not sure. Do you have any ideas.

Try to show a console.log('ngOnDestroy'); in the function, navigate and see if your log is shown