鸿蒙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")
...





相关推荐
Damon小智10 小时前
鸿蒙分布式数据服务(DDS)原理与企业同步实战
分布式·华为·harmonyos
猫林老师16 小时前
HarmonyOS自动化测试与持续集成实战指南
ci/cd·华为·harmonyos
寂然如故16 小时前
拥抱未来:HarmonyOS NEXT 开发新范式深度解析
华为·harmonyos
国霄16 小时前
(2)Kotlin/Js For Harmony——如何复用ViewModel
harmonyos
星释16 小时前
鸿蒙Flutter三方库适配指南:08.联合插件开发
flutter·华为·harmonyos
爱笑的眼睛1117 小时前
HarmonyOS WaterFlow瀑布流布局深度解析:从原理到性能优化
华为·harmonyos
星释17 小时前
鸿蒙Flutter三方库适配指南:06.插件适配原理
flutter·华为·harmonyos
Damon小智20 小时前
鸿蒙元服务深度实践:跨端唤醒与状态共享的设计模式
华为·设计模式·harmonyos
星释21 小时前
鸿蒙Flutter三方库适配指南:07.插件开发
flutter·华为·harmonyos
Damon小智1 天前
HarmonyOS 5 开发:从 Stage 模型看鸿蒙应用生命周期管理
华为·harmonyos