HarmonyOS router.pushNamedRoute子模块与主模块跳转无法同时兼容

通过router.pushNamedRoute在主工程页面跳转到其他模块后,其他模块的页面使用router.pushUrl跳转方法失效,存在子模块与主模块跳转无法同时兼容的问题。

直接启动Testapplication子模块可以跳转,pushUrl方法正常,从主入口通过以下方式进入,pushUrl跳转无效。

主模块Index页面代码:

import ('@BOB/Testapplication/src/main/ets/pages/album')
import router from '@ohos.router';
//执行该方法跳转到子模块'album'页面
router.pushNamedRoute({
  name: 'album', //入口名称
})


Testapplication子模块album页面代码:
import router from '@ohos.router';

@Entry ({ routeName : 'album' })
@Component
struct ablum {
  @State message: string = 'Hi album'
  build() {
    Row() {
      Column() {
        Text(this.message)
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
        Button("pushUrl跳转albumFirst",{ type: ButtonType.Normal, stateEffect: true })
          .borderRadius(8)
          .backgroundColor(0x317aff)
          .width(150)
          .height(60)
          .margin(20)
          .onClick(()=>{
            router.pushUrl({
              url: 'pages/albumFirst',
              // params: new routerParams(this.pageName ,[])
            })//默认模式
          })

          .width('100%')
        // .alignItems(HorizontalAlign.Center)
        // .justifyContent(FlexAlign.Start)
      }
    }
    .height('100%')
  }
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
HarmonyOS
2024-12-26 14:24:45
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
superinsect

当跳转的目标页面属于hsp时(包括hsp页面跳hsp页面),需要使用特定写法,参考:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/in-app-hsp-V5#页面路由跳转

也可以使用路由命名的形式实现,@bundle的方面只支持跳转hsp页面,路由命名支持跳转到hap、hsp、har的页面

分享
微博
QQ
微信
回复
2024-12-26 17:25:03
相关问题
HarmonyOS模块无法跳转
957浏览 • 1回复 待解决
HarmonyOS router跳转navigation跳转
765浏览 • 1回复 待解决
在hsp子模块中如何加载悬浮窗页面
2648浏览 • 1回复 待解决