HarmonyOS nav跳转问题
跳转断点都走了一遍,但是不跳转
代码如下:
import { BreakpointSystem } from '../utils/utils/BreakpointSystem';
import { WindowUtil } from '../utils/utils/WindowUtil';
import { MainPage } from './pages/MainPage';
import { common } from '@kit.AbilityKit';
const TAG = '[App]';
const context = (getContext(this) as common.UIAbilityContext);
// const context = getContext(this).createModuleContext('libgeekapp') as common.UIAbilityContext;
// const context = AppStorage.get('context') as common.UIAbilityContext;
@Entry({ routeName: 'IndexPage' })
@Component
export struct IndexPage {
private breakpointSystem: BreakpointSystem = new BreakpointSystem();
@State context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext
aboutToAppear(): void {
// let bundleName = (getContext(this) as common.UIAbilityContext).applicationInfo.name;
// router.replaceUrl({
// url: `@bundle:${bundleName}/libsplash/ets/pages/SplashPage`
// });
this.breakpointSystem.register();
// let context1: common.UIAbilityContext | undefined = AppStorage.get('context');
WindowUtil.setMissionContinueActive(this.context, true);
// WindowUtil.setMissionContinueActive(context, true);
}
aboutToDisappear() {
//
this.breakpointSystem.unregister();
//
WindowUtil.setMissionContinueActive(this.context, false);
// WindowUtil.setMissionContinueActive(context, false);
}
build() {
Column() {
MainPage()
}
.width('100%')
.height('100%')
}
}
import { CommonSizeConstants } from '../../fontsize/constants/CommonSizeConstants';
import { RouterNameConstants } from '../../routermodule/router1/constants/RouterConstants';
import { RouterModule } from '../../routermodule/router1/utils/RouterModule';
import { BreakpointSystem, BreakpointTypeEnum } from '../../utils/utils/BreakpointSystem';
import { common } from '@kit.AbilityKit';
import { WindowUtil } from '../../utils/utils/WindowUtil';
import { MainConstants } from '../constants/MainConstants';
import { AppUtils } from '../constants/AppUtils';
import { CommonConstants } from '../../utils/common/CommonConstants';
import { TabBarType } from '../model/TabBarModel';
import { CustomTabBar } from '../components/CustomTabBar';
import { ZujianIndex1 } from './index1/ZujianIndex1';
import { ZujianIndex4 } from './index4/ZujianIndex4';
import { SizePreferencesUtil } from '../../fontsize/utils/SizePreferencesUtil';
import SetViewModel from '../../fontsize/model/SetViewModel';
import Logger from '../../fontsize/utils/Logger';
const TAG = '[App]';
const context = (getContext(this) as common.UIAbilityContext);
PersistentStorage.persistProp(MainConstants.profilePath, '');
PersistentStorage.persistProp(MainConstants.showTag, 0);
@Component
export struct MainPage {
@StorageLink(MainConstants.profilePath) profilePath: string = '';
@StorageLink(MainConstants.showTag) showTag: number = 0;
@Prop changeFontSize: number = CommonSizeConstants.SET_SIZE_NORMAL; // 全局字体大小
@State fontSizeText: Resource = $r("app.string.set_size_normal");
@State webViewController: WebviewController | null = null; // 全局WebView
@StorageLink('currentBreakpoint') currentBreakpoint: string = BreakpointTypeEnum.SM; // 全局大屏适配
// private breakpointSystem: BreakpointSystem = new BreakpointSystem();
@State entryHapRouter: NavPathStack = new NavPathStack(); // 全局堆栈跳转
// 业务
@LocalStorageLink('mainTabIndex') currentIndex: TabBarType = TabBarType.index1;
build() {
Navigation(this.entryHapRouter) {
Stack() {
if (this.currentBreakpoint === BreakpointTypeEnum.LG) {
Image($r('app.media.app_icon'))
.width(CommonConstants.FULL_PERCENT)
.height(CommonConstants.FULL_PERCENT)
}
Flex({
direction: this.currentBreakpoint === BreakpointTypeEnum.LG ? FlexDirection.RowReverse : FlexDirection.Column,
}) {
Tabs({ index: this.currentIndex }) {
TabContent() {
// DiscoverView()
ZujianIndex1({ changeFontSize: this.changeFontSize, fontSizeText: this.fontSizeText, })
}
TabContent() {
// LearningView({ learnedId: this.learnedId })
}
TabContent() {
//
}
TabContent() {
ZujianIndex4({
url: 'https://developer.huawei.com/consumer/cn/',
webViewController: $webViewController,
changeFontSize: this.changeFontSize,
fontSizeText: this.fontSizeText,
})
}
TabContent() {
// MineView()
}
}
.layoutWeight(1)
.barHeight(0)
.scrollable(false)
.onChange((index) => {
this.currentIndex = index;
})
CustomTabBar({ currentIndex: $currentIndex })
}
.width(CommonConstants.FULL_PERCENT)
.height(CommonConstants.FULL_PERCENT)
.backgroundColor((this.currentBreakpoint === BreakpointTypeEnum.LG && this.currentIndex === TabBarType.index5) ?
'#00FFFFFF' : '#F1F3F5')
}
}
.title('首页')
.hideTitleBar(true)
.navDestination(this.routerMap)
.mode(NavigationMode.Stack)
}
aboutToAppear() {
// 堆栈
AppUtils.getInstance().init_nav(this.entryHapRouter, RouterNameConstants.ENTRY_HAP);
// 适配
// this.breakpointSystem.register();
// 横竖屏
AppUtils.getInstance().init_display(MainConstants.foldExpanded);
// app前后台状态
// WindowUtil.setMissionContinueActive(context, true);
// 字体
SizePreferencesUtil.getInstance().getChangeFontSize().then((value) => {
this.changeFontSize = value;
this.fontSizeText = SetViewModel.getTextByFontSize(value);
Logger.info("TAG", 'Get the value of changeFontSize: ' + this.changeFontSize);
});
};
aboutToDisappear() {
//
// this.breakpointSystem.unregister();
//
AppUtils.getInstance().del_display(MainConstants.foldExpanded);
//
// WindowUtil.setMissionContinueActive(context, false);
}
onPageShow(): void {
}
onBackPress() {
if (this.webViewController?.accessBackward()) {
this.webViewController.backward();
return true;
}
return false;
}
@Builder
routerMap(builderName: string, param: object) {
// Obtain the WrappedBuilder object based on the module name, create a page through the builder interface, and import the param parameter.
RouterModule.getBuilder(builderName).builder(param);
};
}
HarmonyOS
赞
收藏 0
回答 1
待解决
相关问题
HarmonyOS nav跳转到二级页面后,返回上一级如何刷新页面
433浏览 • 1回复 待解决
HarmonyOS 跳转页面问题
253浏览 • 1回复 待解决
HarmonyOS 跳转问题如下
340浏览 • 1回复 待解决
HarmonyOS router跳转问题
355浏览 • 2回复 待解决
HarmonyOS router路由跳转问题
266浏览 • 0回复 待解决
HarmonyOS 路由跳转回调问题
203浏览 • 1回复 待解决
HarmonyOS 启动页广告跳转问题
126浏览 • 1回复 待解决
HarmonyOS pushNamedRoute 跳转到hsp问题
298浏览 • 1回复 待解决
HarmonyOS 页面跳转刷新问题
506浏览 • 1回复 待解决
HarmonyOS Push点击冷启动跳转问题
286浏览 • 1回复 待解决
Navigation页面跳转的问题
254浏览 • 1回复 待解决
关于Intent跳转桌面问题
7266浏览 • 1回复 待解决
router 路由跳转相关问题
138浏览 • 1回复 待解决
HarmonyOS 子窗口跳转页面的返回问题
115浏览 • 1回复 待解决
HarmonyOS 路由跳转bea1的问题
224浏览 • 1回复 待解决
应用跳转问题怎么处理?
4921浏览 • 1回复 待解决
关于NavPathStack的跳转问题
463浏览 • 1回复 待解决
HarmonyOS 页面导航跳转回调传参问题
451浏览 • 0回复 待解决
HarmonyOS pageInfos.pushPath跳转页面传参问题
269浏览 • 1回复 待解决
JS跳转Java传参问题?
4687浏览 • 1回复 待解决
支付后的路由跳转问题
52浏览 • 1回复 待解决
跨module跳转问题有懂的吗?
592浏览 • 1回复 待解决
HarmonyOS 使用product、features、commons模块开发Page页面跳转问题咨询
216浏览 • 1回复 待解决
提供类似aar包内Activity之间跳转问题
2012浏览 • 1回复 待解决
HarmonyOS使用router跳转页面,跳转无反应
515浏览 • 1回复 待解决
该问题是由于多个navigation使用了同一个NavPathStack导致的,多个navigation需要声明多个NavPathStack。
也可以使用自定义路由表来实现该功能,自定义路由表就是你当前实现的功能,只不过可以将配置项配置在资源文件中,通过资源管理@ohos.resourceManager将文件读取后解析出对应字段。
参考文档:
https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/arkts-navigation-navigation-V5#ZH-CN_TOPIC_0000001847210456__自定义路由表跳转