0
votes

I use nav.push() and nav.pop() for regular navigation, but when I don't want to allow the user to go back (like for example, setting the HomePage after a successful log in), I use nav.setRoot() with lazy loading. I am also calling setRoot('HomePage') to refresh the page when the users update their profile.

However, the problem that I'm experiencing is that the HomePage is getting loaded several times. Even when I press the refresh button in the browser, more instances show up in the console!

I have channelled all the setRoot calls through an event listener in app.component.ts to keep track of how many times it's being called, but everything looks normal. I've tried using appCtrl.getRootNav().setRoot(page, args), but nothing changes.

Any idea where to look? Do I have to manually destroy the pages or clear the navigation stack after calling setRoot?

Thanks!

EDIT (Some code):

Subscription to setRoot event in app.component.ts:

this.events.subscribe('nav:setRoot', (data) => {
  let page = data['page'];
  let args = data['data'];
  if(args !== null && args  !== 'undefined'){
    this.appCtrl.getRootNav().setRoot(page, args);
  }else{
    this.appCtrl.getRootNav().setRoot(page);
  } 
});

From any page, when I want to set a new Root Page:

let arg = { page: 'HomePage'};
this.events.publish('nav:setRoot', arg);
1
Few lines of code is worth a thousand words.Can you share few lines of your code?Sampath
Hi Sampath, I've edited my question to show how I'm doing it. The navigation process doesn't really take that much code. Thanks!EmilioSG

1 Answers

0
votes
ionViewWillUnload() {
    this.events.unsubscribe("nav:setRoot")
}

this worked for me!