HarmonyOS 无感监听navDestinationUpdate的问题

https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-arkui-observer-V5#observeronnavdestinationupdate

使用无感监听navDestinationUpdate时,callback的参数能否支持getConfigInRouteMap方法,能更便于拿取当前route_map的配置信息

HarmonyOS
2024-12-24 16:25:31
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
shlp

在router_map.json中配置的data信息,可以通过onReady回调中执行ctx.getConfigInRouteMap()获取。详见:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/arkts-navigation-navigation-0000001885999037-V5

系统路由表一节

路由拦截也能获取到NavDestinationContext

https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/arkts-navigation-navigation-V5#%E8%B7%AF%E7%94%B1%E6%8B%A6%E6%88%AA

export class NavigationLisenerUtils{
  // isUseInterception: boolean = false;
  registerInterception(isUseInterception: boolean) {
    let pageInfos = AppStorage.get("pageInfos") as NavPathStack
    pageInfos.setInterception({
      willShow: (from: NavDestinationContext | "navBar", to: NavDestinationContext | "navBar",
        operation: NavigationOperation, animated: boolean) => {
        /* let source: NavDestinationContext = from as NavDestinationContext;
        console.error(">>>>>>>>:"+JSON.stringify(source.pathInfo))*/
        if (!isUseInterception) {
          return;
        }
        if (typeof to === "string") {
          console.log("target page is navigation home");
          return;
        }
        let target: NavDestinationContext = to as NavDestinationContext
        console.error(target.getConfigInRouteMap()?.name);
        console.error(target.getConfigInRouteMap()?.pageSourceFile);
        console.error(JSON.stringify(target.getConfigInRouteMap()?.data));
        // redirect target page.Change pageTwo to pageOne.
        // let target: NavDestinationContext = to as NavDestinationContext;
        /*if (target.pathInfo.name === 'pageTwo') {
        target.pathStack.pop();
        target.pathStack.pushPathByName('pageOne', null);
        }*/
      },
      didShow: (from: NavDestinationContext | "navBar", to: NavDestinationContext | "navBar",
        operation: NavigationOperation, isAnimated: boolean) => {
        if (!isUseInterception) {
          return;
        }
        if (typeof from === "string") {
          console.log("current transition is from navigation home");
        } else {
          console.log(`current transition is from ${(from as NavDestinationContext).pathInfo.name}`)
        }
        if (typeof to === "string") {
          console.log("current transition to is navBar");
        } else {
          console.log(`current transition is to ${(to as NavDestinationContext).pathInfo.name}`);
        }
      },
      modeChange: (mode: NavigationMode) => {
        if (!isUseInterception) {
          return;
        }
        console.log(`current navigation mode is ${mode}`);
      }
    })
  }
}
let navigationLisenerUtils = new NavigationLisenerUtils()
export default navigationLisenerUtils as NavigationLisenerUtils
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
分享
微博
QQ
微信
回复
2024-12-24 17:19:25
相关问题
HarmonyOS获取设备标识
1118浏览 • 1回复 待解决
HarmonyOS 转场动画推荐方案
846浏览 • 1回复 待解决
HarmonyOS网络监听问题
909浏览 • 1回复 待解决
HarmonyOS 数组监听问题
701浏览 • 1回复 待解决
HarmonyOS marker设置图片大小问题
639浏览 • 1回复 待解决
HarmonyOS 相机人脸监听相关问题
918浏览 • 1回复 待解决