在我的Ionic 2應用程序中,有兩個頁面,但在ProfilePage
被加載之後,它將推動LoginPage
,然後刷新它並且頁面變爲空白。有誰知道爲什麼會發生這種情況?頁面導航問題ionic2和angular2
這是我的代碼
app.component.ts
import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from 'ionic-native';
import { ProfilePage } from '../pages/profile/profile';
import { LoginPage } from '../pages/login/login';
import { AuthService } from '../services/auth/auth.service';
@Component({
template: `<ion-nav [root]="rootPage"></ion-nav>`
})
export class AuthApp {
rootPage: any = ProfilePage;
constructor(platform: Platform, private auth: AuthService) {
platform.ready().then(() => {
StatusBar.styleDefault();
auth.startupTokenRefresh();
});
}
}
profile.ts
import {Component} from '@angular/core';
import {AuthService} from '../../services/auth/auth.service';
import { NavController } from 'ionic-angular';
import { LoginPage } from '../login/login';
@Component({
templateUrl: 'profile.html',
})
export class ProfilePage {
constructor(public auth: AuthService, public navCtrl: NavController) {
}
ngOnInit() {
console.log(this.auth.authenticated())
if (!this.auth.authenticated()) {
this.navCtrl.setRoot(LoginPage);
}
}
}
login.ts
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
@Component({
templateUrl: 'login.html',
})
export class LoginPage {
authType: string = "login";
error: string;
constructor(public navCtrl: NavController) {}
}
有任何建議什麼我做錯了?爲什麼LoginPage
被推送時會刷新?
控制檯中是否有任何東西? – sebaferreras
沒有在控制檯中 –