ionic4 入门 (三) 完善tabs
创建 界面
cli : ionic g page cart/cart 创建 cart 路径下的 home 界面
cli : ionic g page mine/mine 创建 mine 路径下的 mine 界面
配置路由
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { Routes, RouterModule } from '@angular/router';
import { IonicModule } from '@ionic/angular';
import { TablsPage } from './tabls.page';
import { LoginGuardGuard } from 'src/guard/login-guard.guard';
const routes: Routes = [
{
path: '',
component: TablsPage,
children: [
{
path: '',
// loadChildren: '../home/home/home.module#HomePageModule',
redirectTo: 'home',
pathMatch: 'full'
},
{
path: 'home',
children: [
{
path: '',
loadChildren: '../home/home/home.module#HomePageModule'
}
]
},
{
path: 'classify',
children: [
{
path: '',
loadChildren: '../classify/classify/classify.module#ClassifyPageModule'
}
]
},
{
path: 'cart',
children: [
{
path: '',
loadChildren: '../cart/cart/cart.module#CartPageModule',
canActivate: [LoginGuardGuard]
}
]
},
{
path: 'mine',
children: [
{
path: '',
loadChildren: '../mine/mine/mine.module#MinePageModule',
canActivate: [LoginGuardGuard]
}
]
}
],
},
{
path: '',
redirectTo: 'tabls/home',
pathMatch: 'full'
}
];
@NgModule({
imports: [
CommonModule,
FormsModule,
IonicModule,
RouterModule.forChild(routes)
],
declarations: [TablsPage]
})
export class TablsPageModule {}
html 页面配置
<ion-tabs>
<ion-tab-bar slot="bottom">
<ion-tab-button tab="home">
<ion-icon name = "home"></ion-icon>
<ion-label>首页</ion-label>
</ion-tab-button>
<ion-tab-button tab="classify">
<ion-icon name="apps"></ion-icon>
<ion-label>分类</ion-label>
</ion-tab-button>
<ion-tab-button tab="cart">
<ion-icon name="cart"></ion-icon>
<ion-label>购物车</ion-label>
</ion-tab-button>
<ion-tab-button tab="mine">
<ion-icon name="person"></ion-icon>
<ion-label>我的</ion-label>
</ion-tab-button>
</ion-tab-bar>
</ion-tabs>