我正在寻求有关配置ion-tabs
的帮助,因此这些选项卡位于根目录级别,而不需要子文件夹。因此,我需要/tabs/tab1
而不是/tab1
。
我正在跟踪Ionic Academy以及Ionic和Angular Router的文档。
我使用的是运行ionic start myApp tabs
时获得的默认设置。
最有可能正在更新tabs.router.module.ts
,但不确定是否/如何更新。这是那里的代码。
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { TabsPage } from './tabs.page';
const routes: Routes = [
{
path: 'tabs',
component: TabsPage,
children: [
{
path: 'check-in',
children: [
{
path: '',
loadChildren: '../pages/check-in/check-in.module#CheckInPageModule'
}
]
},
{
path: 'house-manual',
children: [
{
path: '',
loadChildren: '../pages/house-manual/house-manual.module#HouseManualPageModule'
}
]
},
{
path: 'local-area',
children: [
{
path: '',
loadChildren: '../pages/local-area/local-area.module#LocalAreaPageModule'
}
]
},
{
path: '',
redirectTo: '/tabs/check-in',
pathMatch: 'full'
}
]
},
{
path: '',
redirectTo: '/tabs/check-in',
pathMatch: 'full'
}
];
@NgModule({
imports: [
RouterModule.forChild(routes)
],
exports: [RouterModule]
})
export class TabsPageRoutingModule {}
我的最新尝试是在app-routing.module中进行此操作,但是当我将path: 'tabs'
更改为path: ''
时,它将在控制台中以ERROR Error: "[object Object]"
中断。
import { NgModule } from '@angular/core';
import { PreloadAllModules, RouterModule, Routes } from '@angular/router';
import {TabsPage} from './tabs/tabs.page';
const routes: Routes = [
{
path: '',
component: TabsPage,
children: [
{
path: 'check-in',
children: [
{
path: '',
loadChildren: './pages/check-in/check-in.module#CheckInPageModule'
}
]
},
{
path: 'house-manual',
children: [
{
path: '',
loadChildren: './pages/house-manual/house-manual.module#HouseManualPageModule'
}
]
},
{
path: 'local-area',
children: [
{
path: '',
loadChildren: './pages/local-area/local-area.module#LocalAreaPageModule'
}
]
},
{
path: '',
redirectTo: '/check-in',
pathMatch: 'full'
}
]
},
{
path: '',
redirectTo: '/check-in',
pathMatch: 'full'
}
];
@NgModule({
imports: [
RouterModule.forRoot(routes, { preloadingStrategy: PreloadAllModules })
],
exports: [RouterModule]
})
export class AppRoutingModule {}
答案 0 :(得分:2)
实现此目标的简单方法,只需在页面tabs.page.html
的标签按钮中添加以下属性routerLink="/tab1" routerDirection="root"
示例
<ion-tabs>
<ion-tab-bar slot="bottom">
<ion-tab-button routerLink="/tab1" routerDirection="root" tab="tab1">
<ion-icon name="flash"></ion-icon>
<ion-label>Tab One</ion-label>
</ion-tab-button>
<ion-tab-button routerLink="/tab2" routerDirection="root" tab="tab2">
<ion-icon name="apps"></ion-icon>
<ion-label>Tab Two</ion-label>
</ion-tab-button>
<ion-tab-button routerLink="/tab3" routerDirection="root" tab="tab3">
<ion-icon name="send"></ion-icon>
<ion-label>Tab Three</ion-label>
</ion-tab-button>
</ion-tab-bar>
</ion-tabs>
答案 1 :(得分:0)
我发现的最好方法(离子 4):
.ts:
private selectedTab;
constructor(
public translations: TranslationsService,
private navCtrl: NavController
) {
}
async setCurrentTab() {
this.selectedTab = this.tabs.getSelected();
await this.navCtrl.navigateRoot('tabs/' + this.selectedTab);
}
.html:
<ion-tabs #tabs (ionTabsDidChange)="setCurrentTab()">
<ion-tab-bar slot="bottom">
<ion-tab-button tab="home">
<ion-icon class="neosurf-color" src='{{getIcon("home")}}' id="home"></ion-icon>
<ion-label class="neosurf-color">{{translations.__('global.home')}}</ion-label>n-icon class="neosurf-color" src='{{getIcon("locator")}}' id="locator"></ion-icon>
<ion-label class="neosurf-color">{{translations.__('global.locator')}}</ion-label>
</ion-tab-button>n-icon class="neosurf-color" src='{{getIcon("locator")}}' id="locator"></ion-icon>
<ion-label class="neosurf-color">{{translations.__('global.locator')}}</ion-label>
</ion-tab-button>
祝你好运!