HarmonyOS实战开发-Har包内的Page相互跳转

 通过routerName跳转

思路:

当点击 id 为 ThirdHelloWorld 的 Row 组件时,会尝试通过 router.pushNamedRoute 方法跳转到名为 PersonalInformation 的页面。如果跳转成功,不会有额外操作,如果跳转过程中出现错误(捕获到 BusinessError 类型的错误),会将错误信息打印到控制台。

想要进行跳转的page

1.先进行import '@ohos/xxxx' xxx为路径

2.再去pushNamedRoute目标的name

import router from '@ohos.router';
import { BusinessError } from '@kit.BasicServicesKit';
import '@ohos/negative/src/main/ets/pages/PersonalInformation';
import '@ohos/negative/src/main/ets/pages/DeviceManagement';
import '@ohos/negative/src/main/ets/pages/DeviceDetails';


@Component
export struct NegativeOneScreen {
  build() {
    RelativeContainer() {
      // 头部
      Row() {
        Column({ space: 5 }) {
          Text()
            .margin({
              left: 10
            })
          Text().fontSize(20).fontColor(Color.White)
            .margin({
              top: 5,
              left: 20
            })
        }
        .margin({ top: 10, bottom: 5 })
        .alignRules({
          left: { anchor: 'image', align: HorizontalAlign.Start }
        })
      }
      .onClick(() => {
        router.pushNamedRoute({ name: 'PersonalInformation' }).then(() => {
        }).catch((error: BusinessError) => {
          console.info(error.message);
        })
      })
      .id('ThirdHelloWorld').height(100).width('80%').margin({ left: 20 })
    }
    .height('100%').width('100%').backgroundColor('#ff1477b3')
  }
}

目标Page 

1.添加@Entry({routeName:'xxx'}) xxx为目标page的name

// 导入页面路由模块
import router from '@ohos.router';
import { BusinessError } from '@kit.BasicServicesKit';
import { InputMethodListDialog } from '@ohos.inputMethodList';



@Component
@Entry({routeName:'PersonalInformation'})
export struct PersonalInformation {

  build() {
    RelativeContainer() {
    
    }
    .width('100%')
    .height('100%')
  }
}

 

  • 14
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

L.2626

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值