HarmonyOS 鸿蒙Next API升级13后路由跳转NavRouter被禁用

HarmonyOS 鸿蒙Next API升级13后路由跳转NavRouter被禁用

API更新到13后,路由跳转组件NavRouter被禁用

List() {
  ForEach(this.onlineList, (item: Conversation, index: number) => {
    ListItem() {
      NavRouter() {
        myConsultationItem({
          item: item,
          // content:string,
          extra: null
        })

        NavDestination() {
          MessageDialogue({
            converUserInfo: {
              name: JSON.parse(item.content.extra!).commonname ||
              JSON.parse(item.content.extra!).username || 'liu',
              name: this.getCoverName(item),
              userId: item.targetId,
              from: this.from
            }
          })
        }
        .hideTitleBar(true)
      }
    }
  })
}

更多关于HarmonyOS 鸿蒙Next API升级13后路由跳转NavRouter被禁用的实战教程也可以访问 https://www.itying.com/category-93-b0.html

4 回复

从API Version 13 开始,该组件不再维护,推荐使用NavPathStack配合navDestination属性进行页面路由。

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

另外可以对组件进行封装并改用router.pushUrl进行跳转

myConsultationItem({ item: item, extra: null })
  .onClick(() => {
    router.pushUrl({
      url: 'pages/messageDialogue/messageDialogue', params: {
        name: this.getCoverName(item), userId: item.targetId, from: "historical"
      }
    })
  })
}
.margin({ bottom: 20 })

更多关于HarmonyOS 鸿蒙Next API升级13后路由跳转NavRouter被禁用的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


推荐使用NavPathStack,

基本信息

  • 项目名称: NavPathStack
  • 作者: John Doe
  • 版本: 1.0.0
  • 许可证: MIT

深色代码主题

def example_function():
    print("Hello, World!")

在HarmonyOS鸿蒙Next API升级到13后,NavRouter被禁用,开发者需要使用新的导航方式。建议使用RouterNavigator进行页面跳转。Router提供了更灵活的页面跳转和参数传递方式,支持pushreplace等操作。Navigator则适用于基于导航栈的页面管理。具体实现可参考官方文档中关于RouterNavigator的API说明。

回到顶部