this.navCtrl.getActive().name not working after build --prod


#1

Hi,

this.navCtrl.getActive().name works as expected during development however after running

npm run ionic:build -- --prod

I get the following i.e. value = ‘n’ rather than the getActive().name, I think it has to do with webpack?

I am passing data to modal

 public loadPage(pageName?:string): void {
    this.data = {key:'pageName', value:!pageName ? this.navCtrl.getActive().name : pageName};
    this.navCtrl.push('HelpPage', this.data).then(e => {
    });
  }
    {
  "data": {
    "key": "pageName",
    "value": "n",  -- this should be the active page name e.g. "HomePage"
    "opts": {
      "showBackdrop": true,
      "enableBackdropDismiss": true
    }
  }
}

Any help greatly appreciated!


#2

@markwebdev This must be happening because the code is minified when using --prod, and the page name is minified too, so I advise to not rely on that.

One possible solution (I can not guarantee it’s future proof tough) is using the id property:

this.navCtrl.getActive().id

(from what I see, the id has the same value as the one that must be passed to the navCtrl to go to the page).

If you have:

@IonicPage({ 
	name: 'some-page',
	segment: 'some/page/path',
})

the id would be some-page.

I’m assuming you are using it only for reference, not to do some code that depends on the value.

You could also log the object to see all the properties:

log('active', this.navCtrl.getActive())

This can help you to see all the object properties (the object is an instance of ViewController).


#3

Thanks unfortunately id suffers from the same issue due to minification.

I will just pass the hardcoded value to the component as and @input

This should be addressed for PWA’s… hopefully in future releases