[root] is unchangeble because of tabs?


#1

I’m trying to push my app to a page from app.component.ts. I used this tutorial in the docs: https://ionicframework.com/docs/api/navigation/NavController/
Sadly the app doesn’t get pushed to a different page.

app.html

<ion-nav #myNav [root]="rootPage"></ion-nav>

<ion-tabs class="tabs-icon-top">
    <ion-tab tabTitle="Nieuws" tabIcon="custom-news" [root]="tab1"></ion-tab>
    <ion-tab tabTitle="Wedstrijden" tabIcon="custom-games" [root]="tab2"></ion-tab>
    <ion-tab tabTitle="Selectie" tabIcon="custom-players" [root]="tab3"></ion-tab>
    <ion-tab tabTitle="Meer" tabIcon="custom-more" [root]="tab4"></ion-tab>
</ion-tabs>


app.component

import {Component, ViewChild} from '@angular/core';
import {NavController, Platform} from 'ionic-angular';
import {OneSignal} from '@ionic-native/onesignal';

// Pages
import {News} from '../pages/news/news';
import {NewsDetail} from '../pages/news/news-detail';
import {Players} from '../pages/players/players';

@Component({
    templateUrl: 'app.html'
})

export class MyApp {
    @ViewChild('myNav') nav: NavController;

   rootPage: any = News;

    tab1 = News; 
    tab2 = Games;
    tab3 = Players;
    tab4 = MoreLinks;

    constructor(public platform: Platform) {
        platform.ready().then(() => {
            this.nav.push(Players);
});
}
    ngOnInit(){
        this.nav.push(Players);
    }
}

It might have something to do with the tabs since they also use [root]?


#2
export class MyApp {
  rootPage:any;
  constructor(public platform: Platform) {
    platform.ready().then(() => {
      this.rootPage = Players
    })  
  }
}

#3

Apparently the problem has to do with the tabs also having a [root] but i’m not sure how to fix this. If I delete the tabas then the push works >.<’


#4

Ok… what are you trying to do here why your tabs page code is mixed up with the app component code ?


#5

I have a tab menu on every page (that’s why it’s in app.html). And currently i’m getting a notification from OneSignal that will send the user to a specific news item, so I need to push.

If I delete the tabs then the push function works for the notification.

But i can’t get them both to work at the same time. :roll_eyes:


#6

I suggest you take a step back and rethink you project structure maybe take a look here and restructure your app


#7

Oww that works great, thanks I didn’t know you could add them like that.