跳转HSP包页面

如果想在模块A跳转模块B的某个页面,通过

router.pushUrl({url: "xxx"})

url路径需要按照以下格式拼接:

@bundle:包名(bundleName)/模块名(moduleName)/页面相对路径(以main文件夹为起点))

例:

@bundle:com.xxx.xxx/debug/ets/pages/Index

注:跳转的页面需要是在模块B中main_pages.json配置过的页面

跳转HAR包页面

如果想在模块A跳转模块B的某个页面,通过

A模块

import("@ohos/har/src/main/ets/components/mainpage/MainPage")// 引入共享包中的命名路由页面
Button("router  to har ")
.onClick(() => { // 点击跳转到其他共享包中的页面
  console.info("22")
    router.pushNamedRoute({
      name: 'xxxxx',
    })
  // router.pushUrl({ url: '@bundle:com.example.router_har/hsp/ets/pages/Index' })
})

A模块中oh-package.json文件下引入har包

"dependencies": {
    "@ohos/har": "../har"
}

B模块

@Entry({ routeName: 'xxxxx' })
@Component
export struct MainPage {
  @State message: string = "har包页面";
  build() {
    Row() {
      Column() {
        Text(this.message)
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
      }
      .width('100%')
    }
    .height('100%')
  }
}
Logo

讨论HarmonyOS开发技术,专注于API与组件、DevEco Studio、测试、元服务和应用上架分发等。

更多推荐