I’m trying to combine a Side Menu with Tabs. My Side Menu has a set of links different from the ones available in the Tabs. I can visit the pages, but I don’t see the Tabs if I access them via Side Menu.
If I use the links I have in the Homepage of the app, I can get the Tabs everywhere. So what I want is to replicate this across the Side Menu as well.
This is my app.component.ts file:
import { Component, ViewChild } from '@angular/core';
import { Nav, Platform, NavController } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { TabsPage } from '../pages/tabs/tabs';
@Component({
templateUrl: 'app.html'
})
export class MyApp {
@ViewChild('content') nav: Nav;
rootPage: any = TabsPage;
segmentPages: Array<{ title: string; component: any }>;
diseasePages: Array<{ title: string; component: any }>;
constructor(
public platform: Platform,
public statusBar: StatusBar,
public splashScreen: SplashScreen
) {
this.initializeApp();
this.segmentPages = [
{ title: 'Adolescente 12-17', component: 'AdolescentePage' },
{ title: 'Mulher 18-25', component: 'MulherjovemPage' },
{ title: 'Mulher +35', component: 'MulheradultaPage' },
{ title: 'Homem', component: 'HomemPage' }
];
this.diseasePages = [
{ title: 'O Cancro', component: 'CancroPage' },
{ title: 'A Prevenção', component: 'PrevencaoPage' },
{ title: 'O Tratamento', component: 'TratamentoPage' },
{ title: 'A Fertilidade', component: 'FertilidadePage' }
];
}
initializeApp() {
this.platform.ready().then(() => {
this.statusBar.styleDefault();
this.splashScreen.hide();
});
}
openPage(page) {
this.nav.setRoot(page.component);
}
}
and my app.html
<ion-menu [content]="content">
<ion-header>
<ion-toolbar>
<ion-title text-uppercase>Menu</ion-title>
</ion-toolbar>
</ion-header>
<ion-content>
<ion-list>
<ion-list-header>Sou</ion-list-header>
<button menuClose ion-item *ngFor="let p of segmentPages" (click)="openPage(p)">
{{p.title}}
</button>
<ion-list-header>Saber mais sobre</ion-list-header>
<button menuClose ion-item *ngFor="let p of diseasePages" (click)="openPage(p)">
{{p.title}}
</button>
<ion-list-header>Linha de Apoio</ion-list-header>
<ion-item>
<h1 color="primary"><ion-icon name="call"></ion-icon> 808 255 255</h1>
</ion-item>
</ion-list>
</ion-content>
</ion-menu>
<ion-nav id="nav" #content [root]="rootPage" swipeBackEnabled="false"></ion-nav>
This is the code for my Home page (home.ts), which works as desired:
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
constructor(public navCtrl: NavController) {}
goToPage(page) {
this.navCtrl.setRoot(page);
}
}
Why doesn’t setRoot
keep the tabs when I use it inside app.component.ts?