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





相关推荐
条tiao条18 小时前
鸿蒙 ArkTS 实战进阶:从核心组件到面向对象编程一篇通
华为·harmonyos
不羁的木木21 小时前
HarmonyOS文件基础服务(Core File Kit)实战演练02-环境搭建与基础配置
华为·harmonyos
不羁的木木21 小时前
ArkWeb实战学习笔记04-JavaScript与Native通信
笔记·学习·harmonyos
Goway_Hui21 小时前
【 鸿蒙原生应用开发--ArkUI--005 】PomodoroApp 番茄钟应用开发教程
华为·harmonyos
Goway_Hui21 小时前
【鸿蒙原生应用开发--ArkUI--004】NotesApp - 笔记应用教程
harmonyos
想你依然心痛1 天前
HarmonyOS 6(API 23)智能体驱动的沉浸式AR深海科考探索舱
华为·ar·harmonyos·智能体
Goway_Hui1 天前
【鸿蒙原生应用开发--ArkUI--002】CalculatorApp - 计算器应用教程
华为·harmonyos
Goway_Hui1 天前
【鸿蒙原生应用开发--ArkUI--006】WeatherApp - 天气应用教程
华为·harmonyos
不羁的木木1 天前
HarmonyOS文件基础服务(Core File Kit)实战演练03-文件增删改查与目录操作
pytorch·华为·harmonyos