无法在Ionic 4中将标签设为2页

问题描述 投票:1回答:1

我在我的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才能工作。

任何帮助深表感谢。

angular ionic-framework angular-routing ionic4
1个回答
0
投票

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>
© www.soinside.com 2019 - 2024. All rights reserved.