有没有HarmonyOS鸿蒙Next大神能给个建议啥的,一个页面跳转问题折腾了一个星期了,问题描述请看代码备注信息,谢谢
有没有HarmonyOS鸿蒙Next大神能给个建议啥的,一个页面跳转问题折腾了一个星期了,问题描述请看代码备注信息,谢谢
import { AllBillRecordsPage } from '../pages/AllBillRecordsPage';
import { EmptyPagePathStack } from './EmptyPagePathStack';
import { NavigationUtils } from '../util/NavigationUtils';
@Component
export struct RecentRecordsModule {
@State itemModel: Data = Data.getInstance(getContext(this));
@State moduleTitle: string = "最近记录";
@State moduleRedirectContent: string = "查看更多";
@State loadingStatus: LoadingStatus = LoadingStatus.OFF;
@State lazyDataSource: LazyDataSource<DataSource> = this.itemModel.lazyDataSource;
@Consume('appPathStack') appPathStack: NavPathStack;
@Consume('currentIndex') providedCurrentIndex: number;
@StorageLink('currentWidthBreakpoint') currentWidthBreakpoint: string = BreakpointConstants.BREAKPOINT_SM;
}
@Builder
PageMap(name: string) {
if (name === 'AllBillRecordsPage') {
AllBillRecordsPage()
} else {
EmptyPagePathStack()
}
}
build() {
Column() {
Row() {
Text(this.moduleTitle)
.fontSize(16)
.fontColor($r('sys.color.black'))
.fontWeight(FontWeight.Bold)
.layoutWeight(1)
Text(this.moduleRedirectContent)
.fontSize(14)
.fontColor('#9E9E9E')
.onClick(() => {
// 要实现的是点击跳转到这个AllBillRecordsPage页面,但是试了很多方式始终都是跳转到一个带返回按钮的空白页面,没有真机测试,模拟器和预览器都是出现一样的情况。
this.appPathStack.pushPathByName('AllBillRecordsPage', null);
})
}
.width('92%')
.height(12)
.margin({
top: 13,
bottom: 13
})
Column() {
if (this.loadingStatus === LoadingStatus.FAILED) {
LoadingFailedView({ onRetry: () => this.loadResources() })
}
if (this.loadingStatus === LoadingStatus.SUCCESS) {
Column() {
if (this.lazyDataSource.totalCount() > 0) {
LazyForEach(this.lazyDataSource, (item: DataSource) => {
RecentRecordItem({
icon: item.getIcon(),
title: item.getTitle(),
description: item.getDescription(),
amount: item.getAmount(),
date: item.getDate()
})
}, (item: DataSource, index: number) => index + JSON.stringify(item))
} else {
Column() {
Text('暂无记录')
.fontSize(14)
.fontColor('#9E9E9E')
.padding({ top: 15, bottom: 15 })
}
.width('100%')
.alignItems(HorizontalAlign.Center)
}
}
.width('100%')
.padding({ top: 5, bottom: 5 })
}
}
.borderRadius($r('sys.float.corner_radius_level8'))
.margin({ bottom: "5vp" })
.align(Alignment.Center)
.width('92%')
.backgroundColor($r('sys.color.comp_background_list_card'))
}
.width("100%")
.alignItems(HorizontalAlign.Center)
}
鸿蒙新手期盼大神指导,目前练手的程序只要是页面卡片模块点击跳转到某个指定页面都是相同的情况,用阿里lingma分析修改也无济于事,按照CodeGenie 分析给的建议修改也没有效果,已经折腾快十天,求解。
更多关于有没有HarmonyOS鸿蒙Next大神能给个建议啥的,一个页面跳转问题折腾了一个星期了,问题描述请看代码备注信息,谢谢的实战教程也可以访问 https://www.itying.com/category-93-b0.html
更多关于有没有HarmonyOS鸿蒙Next大神能给个建议啥的,一个页面跳转问题折腾了一个星期了,问题描述请看代码备注信息,谢谢的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
感谢大神,一发入魂。
代码贴全一点,PageMap里面的内容需要使用NavDestination包裹,在PageMap或者组件里面都行
已解决,谢谢,
已解决,谢谢,
鸿蒙Next页面跳转可通过router模块实现。在PageAbility中使用router.push()方法跳转,需在config.json中配置目标页面的路由信息。示例代码:
// 当前页面
import router from '@ohos.router'
router.push({
url: 'pages/TargetPage'
})
// config.json
"pages": [
"pages/Index",
"pages/TargetPage"
]
确保两个页面都在config.json中注册,url路径区分大小写。
从代码来看,页面跳转问题可能出在路由配置或页面构建方式上。以下是关键点分析:
-
检查PageMap构建器是否正确注册了AllBillRecordsPage页面。目前代码中虽然定义了PageMap,但缺少NavDestination配置。
-
在AllBillRecordsPage页面中,确保build()方法有正确的内容构建,空白页面通常是因为目标页面没有正确构建UI。
-
尝试改用router.pushUrl方式跳转:
import { router } from '@ohos.router';
...
.onClick(() => {
router.pushUrl({
url: 'pages/AllBillRecordsPage'
})
})
- 确保在main_pages.json中正确配置了路由:
{
"src": [
"pages/AllBillRecordsPage"
]
}
- 如果使用NavPathStack,需要确保堆栈初始化时已包含AllBillRecordsPage的路由信息。
建议先在AllBillRecordsPage的build()方法中添加简单Text组件测试是否能正常显示,排除目标页面构建问题。