【问题标题】:Not able to make a tab work as 2 pages in Ionic 4无法使选项卡在 Ionic 4 中作为 2 页工作
【发布时间】:2019-03-09 16:44:20
【问题描述】:

我在我的 Ionic 4 应用程序中工作,我添加了标签主题,我希望其中一个标签作为 2 路由工作,例如当用户未登录时,登录页面将打开,当用户登录帐户时页面将打开。

这是我的tabs.router.module.ts

import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { TabsPage } from './tabs.page';
import { AuthenticationGuard } from '../guards/authentication.guard';

const routes: Routes = [
  {
    path: 'tabs',
    component: TabsPage,
    children: [
      {
        path: 'tab1',
        children: [
          {
            path: '',
            loadChildren: '../tab1/tab1.module#Tab1PageModule'
          }
        ]
      },
      {
        path: 'tab2',
        canActivate: [AuthenticationGuard],
        children: [
          {
            path: '',
            loadChildren: '../tab2/tab2.module#Tab2PageModule'
          }
        ]
      },
      {
        path: 'tab2/:id',
        canActivate: [AuthenticationGuard],
        children: [
          {
            path: '',
            loadChildren: '../tab2/tab2.module#Tab2PageModule'
          }
        ]
      },
      {
        path: 'acceptchallenge',
        children: [
          {
            path: '',
            loadChildren: '../acceptchallenge/acceptchallenge.module#AcceptchallengePageModule'
          }
        ]
      },
      {
        path: 'tab3',
        children: [
          {
            path: '',
            loadChildren: '../tab3/tab3.module#Tab3PageModule'
          },
          {
            path: '/login',
            loadChildren: '../login/login.module#LoginPageModule'
          }
        ]
      },
      {
        path: '',
        redirectTo: '/tabs/tab1',
        pathMatch: 'full'
      }
    ]
  },
  {
    path: '',
    redirectTo: '/tabs/tab1',
    pathMatch: 'full'
  }
];

@NgModule({
  imports: [
    RouterModule.forChild(routes)
  ],
  exports: [RouterModule]
})
export class TabsPageRoutingModule {}

我想tab3在用户未登录时打开登录页面,当用户登录时打开帐户页面。

所以我必须添加任何 canActivate 才能使其正常工作。

非常感谢任何帮助。

【问题讨论】:

  • 我建议建立一个登录页面,一旦通过身份验证直接进入您的选项卡结构,将帐户页面设置为 root。
  • @JayOrdway。我有一个登录页面,一旦通过身份验证,它将重定向到选项卡页面,但问题是当用户打开登录页面时没有后退按钮?那么,你能帮我解决这个问题吗?
  • 不要路由到没有注销功能的登录页面。如果用户注销,则将用户重定向到登录页面。但不要让他们进入没有注销功能的登录页面。
  • @Najamussaqib。是的,这正在发生。当用户未登录时,他可以访问登录页面,当用户登录时,他无法访问登录页面,但我想在 tab3 上显示登录页面,并且在 tab3 上也显示帐户页面。

标签: angular ionic-framework angular-routing ionic4


【解决方案1】:

在您的tabs.html 中 您可以使用 *ngIf 在用户登录或注销时显示选项卡。取一个 bool 或任何你可以使用的逻辑,并像这样在你的标签页中显示它。

<ion-tab-bar slot="bottom">
    <ion-tab-button tab="profile" *ngIf="userLogin == true">
      <ion-icon name="person"></ion-icon>
      <ion-label>Profile</ion-label>
    </ion-tab-button>

    <ion-tab-button tab="login"  *ngIf="userLogin == false">
      <ion-icon name="settings"></ion-icon>
      <ion-label>Login</ion-label>
    </ion-tab-button>
</ion-tab-bar>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多