我有這個奇怪的問題。用戶登錄時,用戶被轉發到儀表板。但在此之前,我從導航堆棧中刪除登錄頁面,以便當用戶按下硬件返回按鈕時,它們不會被帶回登錄頁面(因爲它們已經登錄)。Ionic 2:從導航堆棧中刪除登錄頁面,導致nav.push在儀表板頁面停止工作
以下是登錄頁面的我的登錄方法
loginUser(){
this.loading=this.loadingctrl.create({
content:"Logging in, please wait..."
});
this.loading.present();
this.ajaxRequest = this.webservice.loginUser(params).subscribe(data => {
this.loading.dismiss();
if(data.status =="ok"){
this.navctrl.push(DashboardPage).then(()=>{
const index = this.viewCtrl.index;
this.navctrl.remove(index);
//Above two lines finds index of current page and removes current page, i.e. login page from navigation stack
});
}else{
//show error alert
}
}, err =>{
this.loading.dismiss();
});
}
此代碼工作得很好,但是卻遇到了一個奇怪的問題
問題
在儀表板的任何按鈕或刷卡菜單沒有按沒有工作。每個鏈接/按鈕調用一些導航到其他頁面的方法。示例方法 -
gotoProductsPage(){
console.log("method gotoProductsPage is called");
this.navCtrl.push(ProductsPage);
}
我可以看到方法被調用,因爲我可以看到日誌被打印在控制檯中。唯一的是this.navCtrl.push(ProductsPage);
似乎不工作。
我在登錄頁面的登錄方法中做了進一步的測試並註釋了行const index = this.viewCtrl.index;
和this.navctrl.remove(index);
。 現在,所有的按鈕的作品。但硬件後退按鈕將用戶帶回登錄頁面。 任何人都可以啓發我爲什麼我的應用程序有這種奇怪的行爲? 謝謝
爲什麼不''this.navCtrl.setRoot(DashboardPage)'? – Duannx