HarmonyOS 无感监听navDestinationUpdate的问题

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

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

HarmonyOS
3天前
浏览
收藏 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
分享
微博
QQ
微信
回复
3天前
相关问题
HarmonyOS获取设备标识
486浏览 • 1回复 待解决
HarmonyOS 转场动画推荐方案
126浏览 • 1回复 待解决
如何减轻icon资源锯齿
1875浏览 • 1回复 待解决
HarmonyOS网络监听问题
335浏览 • 1回复 待解决
HarmonyOS marker设置图片大小问题
40浏览 • 1回复 待解决
ArkUI中icon资源锯齿严重
2131浏览 • 1回复 待解决
HarmonyOS 相机人脸监听相关问题
10浏览 • 1回复 待解决
HarmonyOS 点击事件监听问题
29浏览 • 1回复 待解决
HarmonyOS 键盘事件监听问题
673浏览 • 1回复 待解决