【HarmonyOS NEXT】Entry包跳转HAP包或Feature包失败

打印 上一主题 下一主题

主题 560|帖子 560|积分 1680

【关键字】

跨module包跳转 / Entry / HAP / Feature / Previewer / can't find this page / 页面路由(@ohos.router)/ router.pushUrl / 命名路由
【问题描述】

项目工程包罗三个模块:


  • entry模块:包罗2个页面Index1、Index2
  • library模块(HSP包):包罗1个页面Index
  • feature模块(feature包):包罗1个页面Index
工程中存在跨包跳转,跳转代码参考官网编写:
  1. router.pushUrl({
  2. url : '@bundle:com.***.myapplication/library/ets/pages/Index'
  3. })
复制代码
问题1:当前entry内部Index1可以跳转Index2,但Index2跳转HSP包的Index失败(Previewer模式和模仿器均失败),工具提示“can't find this page”。
问题2:利用模仿器,entry无法跳转到feature包页面。
【解决方案】


  • Previewer模式当前不支持跨module包跳转。
  • 模仿器实现HSP包页面跳转,请确认是否完成如下设置:

    • 在entry包中增长HSP包的引用
      在利用方entry/feature模块的oh-package.json5文件中添加HSP模块引用,以引用名为“sharedlibrary”的HSP为例:
      1. {
      2. ...
      3. "dependencies": {
      4. "sharedlibrary": "file:../sharedlibrary"
      5. }
      6. }
      复制代码
      参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/ide-har-import-0000001547293682
    • 当地调试时将HSP模块一起参加打包
      请按如下方法检察当地调试时是否将HSP模块参加运行:菜单栏选择“Run > Edit Configurations”,选择“Deploy Multi Hap”页签,勾选“Deploy Multi Hap Packages”,选择利用方模块(如entry)和HSP模块(如library),点击“OK”。
      参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/ide-run-debug-configurations-0000001760344518#section393005432811
    • 同时附上Demo供参考

      • entry模块:Index.ets
        1. import router from '@ohos.router'
        2. @Entry
        3. @Component
        4. struct Index {
        5. build() {
        6. Column() {
        7. Text('Hello World1')
        8. .fontSize(50)
        9. .fontWeight(FontWeight.Bold)
        10. Button('跳转')
        11. .margin({top: 50})
        12. .onClick(() => {
        13. router.pushUrl({
        14. url: '@bundle:com.huawei.flexlaout.myapplication/library/ets/pages/Index'
        15. })
        16. })
        17. }
        18. .width('100%')
        19. .height('100%')
        20. }
        21. }
        复制代码

      • entry模块:oh-package-lock.json5
        1. {
        2. "name": "entry",
        3. "version": "1.0.0",
        4. "description": "Please describe the basic information.",
        5. "main": "",
        6. "author": "",
        7. "license": "",
        8. "dependencies": {
        9. "library": "file:../library"
        10. }
        11. }
        复制代码

      • library模块:Index.ets
        1. @Entry
        2. @Component
        3. struct Index {
        4. build() {
        5. Row() {
        6. Column() {
        7. Text('Hello World2')
        8. .fontSize(50)
        9. .fontWeight(FontWeight.Bold)
        10. }
        11. .width('100%')
        12. }
        13. .height('100%')
        14. }
        15. }
        复制代码



  • entry和feature包间的跳转不支持利用router.pushUrl,可通过命名路由的方式跳转。
    参考文档:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/arkts-routing-0000001820879797#ZH-CN_TOPIC_0000001820879797__命名路由

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

吴旭华

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表