簡體   English   中英

Ionic 2 - Sidemenu中的Logout選項卡

[英]Ionic 2 - Logout Tab in Sidemenu

如何在離子2側面菜單中添加Logout選項卡? 如果您已登錄,則表明您正在使用DashboardPage。 現在我有一個菜單項“Logout”,它只是帶我到主頁。 這是app.component.ts中包含所有菜單項的pages數組:

this.pages = [
    {title: 'Dashboard', component: DashboardPage},
    ...
    {title: 'Logout', component: HomePage}
];

但現在我需要在注銷后面添加邏輯,而不僅僅是頁面切換。 當我點擊Logout選項卡而不是僅轉到HomePage時,是否可以調用函數logout()?

編輯:

這是openPage函數:

openPage(page) {
    this.nav.setRoot(page.component);
}

您可以在注銷選項中將組件設置為null

this.pages = [
    {title: 'Dashboard', component: DashboardPage},
    ...
    {title: 'Logout', component: null}
];

然后在你的方法中:

openPage(page) {
    if(page.component) {
        this.nav.setRoot(page.component);
    } else {
        // Since the component is null, this is the logout option
        // ...

        // logout logic
        // ...

        // redirect to home
        this.nav.setRoot(HomePage);
    }
}

我知道這已經得到了解答,但是任何人都可以發現這很有用。

    this.pages = [
        {title: 'Dashboard', component: DashboardPage},
        {title: 'Logout', component: HomePage},
        {title: 'Share', component: ''}
    ];

    openPage(page) {

        switch (true) {

          case ((page.title == 'Logout')): {
            console.log('Clicked Logout button');
            // this.logout(); // call logout logic method
          }
              break;

          case ((page.title == 'Share')): {
            console.log('Clicked Share button');
            // this.share(); call share logic method
          }
              break;

          default: {
            this.nav.setRoot(page.component);
          }
              break;
      }

    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM