Ionic2 Ionic 2返回上一页,从那里它被重定向到登录/注册

Ionic2 Ionic 2返回上一页,从那里它被重定向到登录/注册,ionic2,Ionic2,我正在创建一个应用程序,如果用户试图转到购物车页面,并且用户未登录,则我希望在其中实现,然后将用户重定向回登录页面,并在成功登录后将用户重定向回其所在的源页面。但我无法执行此操作。 下面的一段代码,我正在尝试请让我知道如何做到这一点- //如果用户登录,则检查身份验证 this.storage.get('authid').then((value) =>{ this.apitoken = value; if(this.apitoken == '' || th

我正在创建一个应用程序,如果用户试图转到购物车页面,并且用户未登录,则我希望在其中实现,然后将用户重定向回登录页面,并在成功登录后将用户重定向回其所在的源页面。但我无法执行此操作。 下面的一段代码,我正在尝试请让我知道如何做到这一点- //如果用户登录,则检查身份验证

 this.storage.get('authid').then((value) =>{
        this.apitoken = value;
        if(this.apitoken == '' || this.apitoken == undefined || this.apitoken == null){
            let emsg = this.toast.create({
                message:'Please try again',
                duration:2000
            })
            emsg.present();
            this.navCtrl.popToRoot();
            this.appCtrl.getRootNav().setRoot(Login); //Redirect to login page if not logged in
        }
        else{
            this.storage.get('deviceid').then((val) =>{
                this.dev_id = val;
                this.navCtrl.setRoot(CartPage); // go to cart page.
            })
        }
    })


 Login page - 
 if(data['code'] != 200){
                let errmsg = this.toast.create({
                    message:data['message'],
                    duration:2000
                });
                errmsg.present();
            }
            else{
                let smsg = this.toast.create({
                    message:data['message'],
                    duration:2000
                });
                smsg.present();
                this.storage.set('authid',data['data'].API_CURRENT_TOKEN);
         //Here I am redirecting to Menu page if dircetly click on loginpage but if it has redirected from any other page to login then it should go back to previous page(which is not happening). 
                this.navCtrl.push(Menu,{
                    userInfo:data['data'],
                    is_multiple: 2
                })
                .then(() => {         
                    const index = this.view.index;
                    this.navCtrl.remove(index);
                });
                // this.navCtrl.setRoot(ChangePassword,{'auth':data['data'].API_CURRENT_TOKEN});
            }
请帮我摆脱这种情况。我的登录页面不是模态

谢谢, 直径购物车页面

this.storage.get('authid').then((value) =>{
        this.apitoken = value;
        if(this.apitoken == '' || this.apitoken == undefined || this.apitoken == null){
            let emsg = this.toast.create({
                message:'Please try again',
                duration:2000
            })
            emsg.present();
            this.navCtrl.popToRoot();
            this.appCtrl.getRootNav().setRoot(LoginPage,{previousPage: "CartPage"}, {animate: true, direction: 'forward'}); //Redirect to login page if not logged in and Set Cart page name as previousPage parameter 
        }
        else{
            this.storage.get('deviceid').then((val) =>{
                this.dev_id = val;
                this.navCtrl.setRoot(CartPage); // go to cart page.
            })
        }
    })
腰页

if(data['code'] != 200){
                let errmsg = this.toast.create({
                    message:data['message'],
                    duration:2000
                });
                errmsg.present();
            }
            else{
                let smsg = this.toast.create({
                    message:data['message'],
                    duration:2000
                });
                smsg.present();
                this.storage.set('authid',data['data'].API_CURRENT_TOKEN);
         //Here I am redirecting to Menu page if dircetly click on loginpage but if it has redirected from any other page to login then it should go back to previous page(which is not happening).

                if(navParams.get('previousPage') != "undefined" )
                {
                    this.navCtrl.push(Menu,{
                    userInfo:data['data'],
                    is_multiple: 2
                      })
                    .then(() => {         
                      const index = this.view.index;
                      this.navCtrl.remove(index);
                     });
                }else
                {
                 //Here you get CartPage Name
                   this.navCtrl.push(navParams.get('previousPage'),{
                    userInfo:data['data'],
                    is_multiple: 2
                      });
                 }


                // this.navCtrl.setRoot(ChangePassword,{'auth':data['data'].API_CURRENT_TOKEN});
            }
您可以尝试以下方法:

this.navCtrl.push(this.navCtrl.getPrevious().name);

登录后返回上一页。

我已经尝试过这种方法,但未捕获错误(承诺中):无效链接:CartPage
import{IonicPage}from'ionic angular'@IonicPage({name:“CartPage”})