HarmonyOS 怎么跨模块路由跳转界面

怎么在依赖的user模块里调用entry模块组件

我的entry依赖于user模块,怎么在user组件里点击按钮跳转到entry里面的组件

HarmonyOS
2024-08-29 11:22:40
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
put_get

共享har或者hsp包的跳转,使用router.replaceNamedRoute路由名称跳转(共享包里面的页面,不需要再main_pages里面配置)。

参考链接:

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

【entry跳har/hsp】

import router from ‘@ohos.router’; 
import(‘library/src/main/ets/pages/Index’) // 引入共享包中的命名路由页面,如果存在红色波浪线,不影响编译打包 
@Entry 
@Component 
struct Index { 
 build() { 
  Text(‘点击’).onclick(()=>{ 
   router.pushNamedRoute({ 
    name: ‘harA’ 
   }) 
  }) 
 } 
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.

【harA跳转harB】

@Entry({ routeName : ‘harA’ }) 
@Component 
export struct HarA { 
} 
 
@Entry({ routeName : ‘harA’ }) 
@Component 
export struct HarA { 
 build() { 
  Text(‘点击’).onclick(()=>{ 
   router.pushNamedRoute({ 
    name: ‘harB’ 
   }) 
  }) 
 } 
} 
 
@Entry({ routeName : ‘harB’ }) 
@Component 
export struct HarB { 
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.

由于router不演进,建议采用Navgation作为导航容器:

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

不同模块(har/hsp)页面跳转依赖问题,推荐使用Navigation去实现多模块路由管理和模块间解耦。

参考文档:

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

navigation跨包动态路由:

https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/ui/arkts-navigation-navigation.md#%E8%B7%A8%E5%8C%85%E5%8A%A8%E6%80%81%E8%B7%AF%E7%94%B1

分享
微博
QQ
微信
回复
2024-08-29 16:47:19
相关问题
模块路由跳转的问题有知道的吗?
2724浏览 • 1回复 待解决
HarmonyOS 模块无法跳转
976浏览 • 1回复 待解决
HarmonyOS 模块页面跳转
909浏览 • 1回复 待解决
HarmonyOS 模块的页面路由问题
657浏览 • 1回复 待解决
HarmonyOS 路由跳转怎么接收参数
958浏览 • 1回复 待解决
js怎么跳转java应用界面
6386浏览 • 1回复 待解决
HarmonyOS 怎么取消路由跳转动画
622浏览 • 1回复 待解决
模块间页面跳转怎么
1217浏览 • 1回复 待解决
HarmonyOS 路由跳转咨询
1663浏览 • 1回复 待解决
HarmonyOS router路由跳转问题
1489浏览 • 0回复 待解决
HarmonyOS @Expend模块使用问题
1044浏览 • 1回复 待解决
HarmonyOS 能否模块使用@Styles
780浏览 • 1回复 待解决
HarmonyOS 路由跳转获取跳转传参的方式
2033浏览 • 1回复 待解决