HarmonyOS 鸿蒙Next应用集成sdk后,应用页面如何跳转到har包中的页面
HarmonyOS 鸿蒙Next应用集成sdk后,应用页面如何跳转到har包中的页面
可以通过命名路由跳转到har包中指定页面,首先看har包中的命名路由页面,如以下代码
@Entry({ routeName: ‘staticHarMainPage’})
@Entry
@Component
struct HarMainPage {
@State message: string = ‘Hello World’;
build() {
RelativeContainer() {
Text(this.message)
.id(‘HarMainPageHelloWorld’)
.fontSize(50)
.fontWeight(FontWeight.Bold)
.alignRules({
center: { anchor: ‘container’, align: VerticalAlign.Center },
middle: { anchor: ‘container’, align: HorizontalAlign.Center }
})
}
.height(‘100%’)
.width(‘100%’)
}
}
此时可在har包中封装命名路由的方法进行跳转
export function routerToAnother(context: Context, requestParam: string, callback: AsyncCallback<EmResult>) {
hilog.info(0x00000, TAG, ‘routerToAnother’);
router.pushNamedRoute({
name: ‘staticHarMainPage’,
params: requestParam
}, data => {
if (data) {
hilog.error(0x00000, TAG, ‘跳转失败:’ + JSON.stringify(data));
return;
}
hilog.info(0x00000, TAG, ‘跳转成功’);
hilog.info(0x00000, TAG, ‘传入的context:’ + JSON.stringify(context));
context.eventHub.on(‘care’, callback)
})
}
这样外部使用的时候无需关注命名路由的变化,便捷性增加,且不用担心混淆带来的影响
更多关于HarmonyOS 鸿蒙Next应用集成sdk后,应用页面如何跳转到har包中的页面的实战教程也可以访问 https://www.itying.com/category-93-b0.html
1 回复