Ionic2 Ionic 2:从导航堆栈中删除登录页面,导致nav.push在仪表板页面中停止工作
我有一个奇怪的问题。当用户登录时,用户将被转发到仪表板。但在此之前,我从导航堆栈中删除了登录页面,这样当用户 按硬件返回按钮,它们不会返回登录页面(因为它们已经登录) 下面是我登录页面的登录方法Ionic2 Ionic 2:从导航堆栈中删除登录页面,导致nav.push在仪表板页面中停止工作,ionic2,Ionic2,我有一个奇怪的问题。当用户登录时,用户将被转发到仪表板。但在此之前,我从导航堆栈中删除了登录页面,这样当用户 按硬件返回按钮,它们不会返回登录页面(因为它们已经登录) 下面是我登录页面的登录方法 loginUser(){ this.loading=this.loadingctrl.create({ content:"Logging in, please wait..." }); this.loading.present(); th
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)代码>似乎不起作用
我做了进一步的测试并注释了这些行constindex=this.viewCtrl.index
和this.navctrl.remove(索引)登录页面的登录方法中的代码>。
现在所有的按钮都工作了。但“硬件后退”按钮将用户带回登录页面。
有人能告诉我为什么我的应用程序有这种奇怪的行为吗??
谢谢没有理由通过尝试获取登录页面索引并删除它来操纵导航堆栈。
我建议只需将仪表板页面设置为导航堆栈的根
if(data.status =="ok"){
this.navctrl.setRoot(DashboardPage).then(()=>{
console.log("done");
});
}else{
//show error alert
}
现在它将无法导航到返回的登录页面
为什么不执行此操作。navCtrl.setRoot(仪表板页面)
?我愚蠢的错误,我怎么能忽略这一点。谢谢