HarmonyOS 鸿蒙Next HMRouter使用问题
HarmonyOS 鸿蒙Next HMRouter使用问题
如图所示,在使用HMRouter的时候出现了编译问题,出现这种情况的场景是:A页面跳转B页面,A页面写了
HMRouterMgr.push({pageUrl:BPage})
B页面写了
@HMRouter({
pageUrl: BPage,
singleton:true
})
这个时候是正常能运行的,也能跳转的,但是如果我在B页面写了一些代码,其中引用了其他类,例如下面这个dialog工具类,就会报运行失败,失败的错误日志在上面,感觉没啥用。
@CustomDialog
export struct CommonDialog {
@Link showButtonLeft: boolean;
@Link showButtonRight: boolean;
@Link CommonDialogTitle: string
@Link CommonDialogButtonLeft: string
@Link CommonDialogButtonRight: string
cancel: () => void = () => {
}
confirm: () => void = () => {
}
controller: CustomDialogController = new CustomDialogController({
builder: CommonDialog({
showButtonLeft: $showButtonLeft,
showButtonRight: $showButtonRight,
CommonDialogTitle: $CommonDialogTitle,
CommonDialogButtonLeft: $CommonDialogButtonLeft,
CommonDialogButtonRight: $CommonDialogButtonRight
}),
})
build() {
RelativeContainer() {
Column() {
Text(this.CommonDialogTitle)
.fontSize(20)
.margin(10)
Divider()
.width('100%')
.height(1)
.backgroundColor($r("app.color.colorF5F5F5"))
Row() {
Text(this.CommonDialogButtonLeft)
.fontSize(13)
.fontColor($r('app.color.color2B2B2B'))
.padding(15)
.layoutWeight(1)
.textAlign(TextAlign.Center)
.backgroundColor($r('app.color.colorFFFFFF'))
.border({
width: 1,
color: $r('app.color.colorFFFFFF'),
radius: 10,
style: BorderStyle.Solid
})
.visibility(this.showButtonLeft ? Visibility.Visible : Visibility.None)
.onClick(() => {
if (this.controller != undefined) {
this.cancel()
this.controller.close()
}
})
Divider()
.vertical(true)
.color($r("app.color.color505050"))
.visibility(this.showButtonLeft && this.showButtonRight ? Visibility.Visible : Visibility.None)
.width(1)
.height(45)
Text(this.CommonDialogButtonRight)
.fontSize(13)
.fontColor($r('app.color.color2B2B2B'))
.padding(15)
.layoutWeight(1)
.textAlign(TextAlign.Center)
.backgroundColor($r('app.color.colorFFFFFF'))
.border({
width: 1,
color: $r('app.color.colorFFFFFF'),
radius: 10,
style: BorderStyle.Solid
})
.visibility(this.showButtonRight ? Visibility.Visible : Visibility.None)
.onClick(() => {
if (this.controller != undefined) {
this.confirm()
this.controller.close()
}
})
}
.height(45)
}
.alignRules({
top: { anchor: '__container__', align: VerticalAlign.Top },
left: { anchor: '__container__', align: HorizontalAlign.Start },
right: { anchor: '__container__', align: HorizontalAlign.End },
bottom: { anchor: '__container__', align: VerticalAlign.Bottom }
})
.border({
width: 1,
color: $r('app.color.colorFFFFFF'),
radius: 10,
style: BorderStyle.Solid
})
.width('80%')
.height('auto')
.backgroundColor($r('app.color.colorFFFFFF'))
}
}
}
更多关于HarmonyOS 鸿蒙Next HMRouter使用问题的实战教程也可以访问 https://www.itying.com/category-93-b0.html
报错看不出和你的代码有关;建议你重新clean后 再启动;如果还有报错 就不你的完整代码发下看看。
更多关于HarmonyOS 鸿蒙Next HMRouter使用问题的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
好像跟我之前的问题很相似,https://developer.huawei.com/consumer/cn/forum/topic/0201170269078167460?fid=0109140870620153026
可能是已知问题,不行的话,到gitee上代码库留言,应该有专业人员解答。
HarmonyOS Next中的HMRouter主要用于页面路由和跳转,支持通过URL或页面名称进行导航。使用时需确保在config.json中正确配置路由信息,包含页面路径和名称。HMRouter提供的方法包括push
、replace
、back
等,用于实现页面跳转和返回操作。若遇到路由失败,检查配置和路径是否正确,并确保页面已正确注册。