app.getActiveNav().getActive() is undefined

when it comes to last page(HomePage), I want to exit app.

but the problem is that weirdly,
app.getActiveNav().getActive() is undefined.
and

I took a look closer on app.getActiveNav()
(I checked Log and saw undefined on root)

my code is located in app.components.ts

   platform.registerBackButtonAction(() => {
        let nav = this.app.getActiveNav().getActive()
        let activeView = nav.getActive();
      
      console.log("back pressed");
      console.log(nav)
      console.log(activeView)
           nav.pop();
          });

weirdly , I came to second page from homepage,
when I press back button on hardware,
it says no views in the stack to be removed
(I came to second page by using navCtrl.push())

What I would do instead is to put this code only on the page where you want it to be active, and use lifecycle events to register and deregister.