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
2024-08-29 09:25:19
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
zbw_apple

该问题是由于多个navigation使用了同一个NavPathStack导致的,多个navigation需要声明多个NavPathStack。

也可以使用自定义路由表来实现该功能,自定义路由表就是你当前实现的功能,只不过可以将配置项配置在资源文件中,通过资源管理@ohos.resourceManager将文件读取后解析出对应字段。

参考文档:

https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/arkts-navigation-navigation-V5#ZH-CN_TOPIC_0000001847210456__自定义路由表跳转

分享
微博
QQ
微信
回复
2024-08-29 17:22:24
相关问题
HarmonyOS 跳转问题如下
540浏览 • 1回复 待解决
HarmonyOS router跳转问题
517浏览 • 2回复 待解决
HarmonyOS 跳转页面问题
396浏览 • 1回复 待解决
HarmonyOS router路由跳转问题
491浏览 • 0回复 待解决
HarmonyOS 方法点击跳转问题
170浏览 • 1回复 待解决
HarmonyOS 页面跳转刷新问题
892浏览 • 1回复 待解决
HarmonyOS 路由跳转回调问题
332浏览 • 1回复 待解决
HarmonyOS 启动页广告跳转问题
270浏览 • 1回复 待解决
HarmonyOS pushNamedRoute 跳转到hsp问题
481浏览 • 1回复 待解决
HarmonyOS Push点击冷启动跳转问题
439浏览 • 1回复 待解决
HarmonyOS 子窗口跳转页面的返回问题
262浏览 • 1回复 待解决
HarmonyOS 路由跳转bea1的问题
356浏览 • 1回复 待解决
应用跳转问题怎么处理?
5092浏览 • 1回复 待解决
关于NavPathStack的跳转问题
667浏览 • 1回复 待解决
关于Intent跳转桌面问题
7427浏览 • 1回复 待解决
router 路由跳转相关问题
353浏览 • 1回复 待解决
Navigation页面跳转问题
463浏览 • 1回复 待解决
HarmonyOS 页面导航跳转回调传参问题
1014浏览 • 0回复 待解决
支付后的路由跳转问题
249浏览 • 1回复 待解决
JS跳转Java传参问题
4817浏览 • 1回复 待解决
跨module跳转问题有懂的吗?
703浏览 • 1回复 待解决