【发布时间】:2018-05-25 07:08:15
【问题描述】:
该应用程序很简单,它结合了侧边菜单和选项卡。我认为它完美无缺,但直到我发现导航到root page 然后点击浏览器上一个按钮会导致导航栏出现奇怪的闪烁。
这是output 我到目前为止。
Menu.ts
import { Component,ViewChild } from '@angular/core';
import { IonicPage, NavController, NavParams, Nav } from 'ionic-angular';
export interface PageInterface {
title: string;
pageName: string;
tabComponent?: any;
index?: number;
icon: string;
}
// Am I doing some mistakes in the following block?
@IonicPage({
})
@Component({
selector: 'page-menu',
templateUrl: 'menu.html'
})
export class MenuPage {
rootPage ="TabsPage";
@ViewChild(Nav) nav: Nav;
pages: PageInterface[]= [
{ title:'Tab 1', pageName: 'TabsPage', tabComponent: 'HomePage', index: 0, icon:'home' },
{ title:'Tab 2', pageName: 'TabsPage', tabComponent: 'SchedulePage', index: 1, icon:'timer' },
{ title:'Tab 3', pageName: 'TabsPage', tabComponent: 'CasesPage', index: 2, icon:'briefcase' },
{ title:'Non-Tab', pageName: 'SplashPage', icon:'information-circle' }
]
constructor(public navCtrl: NavController, public navParams: NavParams) {
}
openPage(page: PageInterface) {
let params = {};
if (page.index) {
params = { tabIndex: page.index};
}
if (this.nav.getActiveChildNavs().length && page.index != undefined) {
this.nav.getActiveChildNavs()[0].select(page.index);
console.log('Else executed umdefined');
} else {
// This is where I set new root page if it is not a tabbed page.
this.nav.setRoot(page.pageName, params).catch((err: any) => {
console.log(`Didn't set nav root: ${err}`);
});
}
}
isActive(page: PageInterface) {
let childNav = this.nav.getActiveChildNavs()[0];
if (childNav) {
if (childNav.getSelected() && childNav.getSelected().root === page.tabComponent) {
return 'primary';
}
return;
}
if (this.nav.getActive() && this.nav.getActive().name === page.pageName) {
return 'primary';
}
return;
}
ionViewDidLoad() {
console.log('MenuPage');
}
}
Tabs.ts
@IonicPage({
segment: 'page-tabs'
})
@Component({
templateUrl: 'tabs.html'
})
export class TabsPage {
tab1Root= 'HomePage';
tab2Root= 'SchedulePage';
tab3Root= 'CasesPage';
myIndex: number;
constructor(public navCtrl: NavController, public navParams: NavParams) {
}
}
如果信息不充分,整个项目都可用here。
更新 我无法更清楚地解释,但如果您尝试运行项目并在从选项卡式页面切换到非选项卡式页面时观察 URL,问题似乎来自导航历史。
【问题讨论】:
-
你在设备上测试过吗?
-
你使用
@ViewChild(Nav) nav: Nav;而不是navCtrl有什么原因吗? -
@ewizard 在 Ionic DevApp 上对其进行了测试,并且发生了闪烁。与 Chrome 相同。
-
我真的开始学习 Ionic。 Ionic Conference App 使用@ViewChild(Nav) nav: Nav;所以我确实遵循了。我应该如何使用 navCtrl 而不是 @ViewChild?
-
也许只有我一个人,但如果不是侧边菜单,它似乎正在重置汉堡图标...您是否尝试过仅使用侧边菜单而没有选项卡的 navroot 切换?
标签: ionic-framework tabs