You can get the active page and check its name:
public isActive(pageName: string): boolean { return this.navCtrl.getActive().name === pageName); }
UPDATE
In the comments, you can see some users who claim that this solution does not work for them because of the Uglify process. That sounds reasonable, but I still found a solution that seems to work. I compiled an APK with this code using the following command:
ionic cordova build android --prod --release
At compile time, you can see:
... [13:00:41] uglifyjs started ... [13:00:43] sass finished in 2.45 s [13:00:43] cleancss started ... [13:00:46] cleancss finished in 3.05 s [13:00:57] uglifyjs finished in 16.27 s ...
Then, when I launched this application in the Android emulator, I got the name of the right page using this.navCtrl.getActive().name .
I must say that I did not test it with a signed application on a real device.
Maybe Android or the emulator will not be affected, maybe the problem described by these users has been resolved in recent releases, maybe I'm doing something wrong. Since I do not know the answer to these questions, I keep my answer, but I added this information. Please, if you know more about this comment, instead of just ignoring or postponing the answer. If this answer turns out to be erroneous, I will gladly change it or delete it.
source share