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%')
  }
阅读 628
1 个回答
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进