Navigation返回到栈中指定页面时,onPop不生效是怎么回事?

import { promptAction } from "@kit.ArkUI"

const stack = new NavPathStack()

@Entry
@Component
export struct Index {
@Builder
PageMap(name: string) {
if (name === "second") {
Second()
} else if (name === "third") {
Third()
} else if (name === "forth") {
Forth()
}
}

build() {
Navigation(stack) {
Text('首页')
.margin({ top: 50 })
.onClick(() => {
stack.pushPath({
name: "second",
onPop: () => {

}
})
})
}
.mode(NavigationMode.Stack)
.navDestination(this.PageMap)
}
}

@Component
export struct Second {
build() {
NavDestination() {
Text('页面二,点击进入页面三')
.margin({ top: 50 })
.onClick(() => {
stack.pushPath({
name: "third",
onPop: (popInfo: PopInfo) => {
promptAction.showToast({
message: '返回结果为' + popInfo.result as string
})
}
})
})
}
}
}


@Component
export struct Third {
build() {
NavDestination() {
Text('页面三,点击进入页面四')
.margin({ top: 50 })
.onClick(() => {
stack.pushPath({
name: "forth",
onPop: () => {

}
})
})
}
}
}

@Component
export struct Forth {
build() {
NavDestination() {
Text('页面四,点击返回页面二')
.margin({ top: 50 })
.onClick(() => {
stack.popToName('second', 'aaaaaaaa')
})
}
}
}


如案例所示,首页->Second->Third->Forth,从Forth直接返回Second,携带的参数在onPop里接收不到

HarmonyOS
HarmonyOS Next
2025-03-31 10:11:47
浏览
收藏 0
回答 0
待解决
相关问题
SDK tools 没有内容怎么回事
1577浏览 • 1回复 待解决
模拟器突然启动不了怎么回事
6412浏览 • 1回复 待解决
返回页面触发aboutToAppear
5397浏览 • 1回复 待解决
ArkUI 横屏应用自动重启怎么回事
3091浏览 • 1回复 待解决
ohpm安装失败怎么回事
3654浏览 • 1回复 待解决
PopupDialog 不显示怎么回事
8630浏览 • 2回复 待解决
不能下载SDK怎么回事
3546浏览 • 1回复 待解决