Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70747

How can I detect navigation returning to a parent page?

$
0
0

@ZaLiTHkA wrote:

Greetings,

I’m building an Ionic 4 Angular app that has tabs as the initial view, where the main tab provides the means to navigate to a component inside a lazy-loaded module. I would like to run some custom logic inside this initial main tab component whenever it becomes the currently active page, which I’ve got working for all scenarios except when the app navigates back from the “Detail” component.

For reference, the routes defined in my main app-routing.module.ts are as follows:

[
  { path: '', redirectTo: '/tabs/home', pathMatch: 'full' },
  {
    path: 'tabs',
    component: TabsPage,
    children: [
      { path: 'home', component: HomePage }
    ]
  },
  { path: 'detail', loadChildren: './detail/detail.module#DetailPageModule' }
]

…and I’m currently navigating from HomePage to DetailPage (obviously, within DetailPageModule) using a button that calls the following function:

viewDetail(data: CustomData) {
  this.navCtrl.navigateForward('detail', {
    state: data
  });
}

The data: CustomData part doesn’t affect my current issue directly, but I’m leaving it in the snippet to make it clear that I need to pass data along when navigating to DetailPage

As a quick test, I implemented all of the Ionic 4 and Angular 8 lifecycle hooks in both the HomePage and DetailPage components with a simple console.log() call so I could inspect the behaviour while I navigated around my app, but I cannot find anything that triggers inside my HomePage component when I navigate back from the DetailPage component…

I’ve searched for posts from other people with the same issue, found a few that are really close, but I couldn’t glean any knowledge from those posts/issues/articles that helped me in any way.

I’ve also tried to make use of a static method in HomePage that I can call from a lifecycle hook in DetailPage, but this doesn’t give me access to any of the methods I’ve defined in HomePage, so that doesn’t work for me.

Is there anything I can do with the current app structure to achieve this? Do I perhaps need to structure my app components differently to create a scenario in which I can detect this navigation? If so, what would you suggest?

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70747

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>