Ionic 4 Page Lifecycle Problem

Hİ, When I add the following code to my app, the app closes when I press the back key of the phone when I enter the new page.

This code still works when you go to any page from the homepage. I want this code to don’t run on another page from the homepage

home.page.ts

.....
subscription: any;
.....
ionViewWillEnter(){
    this.subscription = this.platform.backButton.subscribe(()=>{
      navigator['app'].exitApp();
    });
  }

  ionViewWillLeave(){
    this.subscription.unsubscribe();
  }

This forum is dead! No one is helping.

Sir, i think you need to describe you question in detail so other member can understand your problem.

according to your problem description that behavior is absolutely correct because you subscribe backbutton event and write exitapp code within subscription. we don’t know in which page you write that code (i mean in app.component or other page) so one can can help with your problem until they understand full use case.

no one can understand what is your issue and what you want to do so i suggest you to give more detail of your problem.

1 Like

I wrote it on the home.page.ts code. This code still works when you go to any page from the homepage. I want this code to don’t run on another page from the homepage

and i think home is your default rounting page right ?
default means routepath=’’ in rounting.module

Yes, it is. home is my default rounting page. (20 character!)

probably home page is not good place to configure back button event
i don’t know you search in forum for it but may be this link help you how to configure it in best way

1 Like

I will try thank you so much.

This code not work. :frowning: