无法使选项卡在 Ionic 4 中作为 2 页工作
Not able to make a tab work as 2 pages in Ionic 4
我在我的 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
才能正常工作。
非常感谢任何帮助。
在你的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>
我在我的 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
才能正常工作。
非常感谢任何帮助。
在你的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>