Hello friends I would appreciate your help, I’ve been trying to solve this problem for a week.
Error:
the error is when in app.component.ts valid if the user is logged in redirected to Menupage that shows a tab menu combined with sidebar, when the redirection is done the menu page loads twice and this makes the menu disappear.
Ionic:
ionic (Ionic CLI) : 4.7.1 (/home/ereyes/.nvm/versions/node/v8.12.0/lib/node_modules/ionic)
Cordova:
cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1)
Cordova Platforms : not available
Cordova Plugins : not available
System:
NodeJS : v8.12.0 (/home/ereyes/.nvm/versions/node/v8.12.0/bin/node)
npm : 6.4.1
OS : Linux 4.15
app.component.ts:
export class MyApp {
rootPage:any = ‘LoginPage’;
private app;
private platform;
pages;
authState: any = null;
@ViewChild(Nav) nav: Nav;
constructor(private zone: NgZone,app: App, platform: Platform,private statusBar: StatusBar, splashScreen: SplashScreen,private auth: AuthService) {
this.app = app;
this.platform = platform;
this.initializeApp();
}
initializeApp() {
this.platform.ready().then(() => {
this.statusBar.styleDefault();
});
this.auth.afAuth.authState.subscribe( user => {
console.log('user----------- '+user);
if ( user ){
this.rootPage = ‘MenuPage’;
//console.log('user '+ JSON.stringify(user));
}else{
this.rootPage = ‘LoginPage’;
//console.log('not logged: '+ JSON.stringify(user));
}
});
}
}
menu.ts:
export class MenuPage {
rootPage = ‘TabsPage’;
@ViewChild(Nav) nav: Nav;
pages: PageInterface = [
{title: ‘Perfil’, pageName: ‘ProfilePage’, index: 1, icon: ‘person’ },
{title: ‘Mis Direcciones’, pageName: ‘ProfilePage’, index: 1, icon: ‘md-map’ },
{title: ‘Historico de Pedidos’, pageName: ‘ProfilePage’, index: 1, icon: ‘ios-list-box-outline’ },
]
constructor(public navCtrl: NavController, public navParams: NavParams,private auth: AuthService) {
}
openPage(page: PageInterface) {
let params ={};
this.nav.setRoot(page.pageName, params, { animate: true, duration: 600, direction: ‘backward’ });
}
logout() {
this.auth.signOut();
this.nav.setRoot(‘LoginPage’);
}
}
best regards