I need to know which page is open when I have tabs.
I have the following situation:
I navigate from page that is from the tabs to page that isn’t. Than I open the same page through the sidebar.
How do I know that the page is already open and prevent it from opening?
For example from “Home” page, click on “Go to News page” button.
How to know that “News” page is open and to prevent it from opening form sidebar? example
checkpage(){
let checkViews = this.navCtrl.getAllChildNavs();
if(checkViews.component == News){
console.log('News is already in the Navstack!);
}else{
this.navCtrl.push(News);
}
}
By default, the app opens the “home” page which is in tabs.
In “home” page there is a link to “news” page.
But when I click on that button and open the “news” page in this.navCtrl.getAllChildNavs() it will only be “tabs” page
So in conclusion you didn’t open News-Page yet because it only shows “tabs-Page” in the navStack. Nothing wrong here. Maybe I got your question wrong if so please explain exactly what you want to achieve since the code I’ve provided you is working fine.
Ah so you want to prevent it when its already ACTIVE and not just in the navStack.
Change the code to this and it should work just fine:
checkpage(){
let checkViews = this.navCtrl.getActive();
if(checkViews.component == News){
console.log('News is already in the Navstack, don't push!);
}else{
console.log('No Newspage open you can push!');
}
}
pushToNews(){
this.checkpage();
}
You can use pushToNews for your Button or you can also use checkpage for your Button its up to you. What this code does = it checks wich Page is currently open. If News is currently open it will give you ELSE if its not open it will give u IF.