鸿蒙Navigation路由能力汇总

基本使用步骤:

1、新增配置文件router_map:

2、在moudle.json5中添加刚才新增的router_map配置:

3、使用方法:

属性汇总:

https://developer.huawei.com/consumer/cn/doc/harmonyos-references/ts-basic-components-navigation

https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/arkts-navigation-navigation-V5

子页面通过OnReady回调获取参数:

复制代码
@Component
export struct PageOne {
  pathStack: NavPathStack = new NavPathStack()

  build() {
    NavDestination() {
      ...
    }.title('PageOne')
    .onReady((context: NavDestinationContext) => {
      this.pathStack = context.pathStack
    })
  }
}

更多属性:

复制代码
@Entry
@Component
struct Index {
  pathStack: NavPathStack = new NavPathStack()

  build() {
    // 设置NavPathStack并传入Navigation
    Navigation(this.pathStack) {
        ...
    }.width('100%').height('100%')
  }
  .title("Navigation")
}



// push page
this.pathStack.pushPath({ name: 'pageOne' })

// pop page
this.pathStack.pop()
this.pathStack.popToIndex(1)
this.pathStack.popToName('pageOne')

// replace page
this.pathStack.replacePath({ name: 'pageOne' })

// clear all page
this.pathStack.clear()

// 获取页面栈大小
let size = this.pathStack.size()

// 删除栈中name为PageOne的所有页面
this.pathStack.removeByName("pageOne")

// 删除指定索引的页面
this.pathStack.removeByIndexes([1,3,5])

// 获取栈中所有页面name集合
this.pathStack.getAllPathName()

// 获取索引为1的页面参数
this.pathStack.getParamByIndex(1)

// 获取PageOne页面的参数
this.pathStack.getParamByName("pageOne")

// 获取PageOne页面的索引集合
this.pathStack.getIndexByName("pageOne")
...





相关推荐
Random_index44 分钟前
#HarmonyOS篇:学习UI规范基本语法&&学习UI范式装填管理V1&&学习UI范式装填管理V2&&学习UI范式渲染控制
harmonyos
前端世界1 小时前
鸿蒙分布式权限管理实战指南:架构原理 + 可运行 Demo
分布式·架构·harmonyos
前端世界2 小时前
鸿蒙分布式通信安全实践:中间人攻击原理与防御实现
分布式·华为·harmonyos
11 小时前
鸿蒙——通知
华为·harmonyos·
周胡杰14 小时前
鸿蒙preferences单多例使用,本地存储类
缓存·华为·harmonyos·preferences·鸿蒙本地存储
IvanCodes14 小时前
[鸿蒙2025领航者闯关] 共享终端的隐形守护者:基于 HarmonyOS 6 的全链路隐私闭环实战
华为·harmonyos·鸿蒙
芒鸽19 小时前
鸿蒙PC上FFmpeg+Electron的Encode Smoke(P2) 排错实录:从“无法播放/时长为 0”到“保留画面且转完整时长”
ffmpeg·electron·harmonyos
2501_9444490821 小时前
帮助中心页面 Cordova&OpenHarmony 混合开发实战
harmonyos
搬砖的kk1 天前
在鸿蒙PC上开发鸿蒙应用:一场从协同到高效的技术之旅
华为·harmonyos
Tipriest_1 天前
华为鸿蒙/OpenHarmony 的设备调试工具hdc介绍
华为·harmonyos·hdc