When I built and ran my app on android, I realized that the hardware back button is not working. I Have the main page, which has two children, a home and a favorite page, where the home page is the default page. If I am at the Favourites page and I click the back button, it takes me to the home page, but from the home page, if I click the back button, it shows a white screen and restarts the app after few seconds. I would only be able to close the app if I click it three times. I am using ionic 4, Angular 8.
Here is how my app route looks like:
{ path: '', loadChildren: './pages/main/main.module#MainPageModule' },
{ path: 'search', loadChildren:
'./pages/search/search.module#SearchPageModule' },
{ path: 'catalog-view', loadChildren: './pages/cat-view/cat-
view.module#CatViewPageModule' },
and here is what my main module looks like:
const routes: Routes = [
{
path: 'main',
component: MainPage,
children: [
{ path: 'home', loadChildren: '../home/home.module#HomePageModule' },
{ path: 'favorites', loadChildren:
'../favorites/favorites.module#FavoritesPageModule' },
]
},
{
path: '',
redirectTo: '/main/home'
}
];
I tried to add this functionality at the homePage, then the Main, and even the Appcompomponent, but nothing works:
ionViewDidEnter(){
this.subscription = this.platform.backButton.subscribe(()=>{
navigator['app'].exitApp();
});
}
ionViewWillLeave(){
this.subscription.unsubscribe();
}