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')
})
}
}
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.


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

HarmonyOS
HarmonyOS Next
8天前
浏览
收藏 0
回答 0
待解决
相关问题
SDK tools 没有内容怎么回事
1215浏览 • 1回复 待解决
模拟器突然启动不了怎么回事
4715浏览 • 1回复 待解决
返回页面触发aboutToAppear
4425浏览 • 1回复 待解决
ArkUI 横屏应用自动重启怎么回事
2671浏览 • 1回复 待解决
PopupDialog 不显示怎么回事
8171浏览 • 2回复 待解决
ohpm安装失败怎么回事
3173浏览 • 1回复 待解决
不能下载SDK怎么回事
2963浏览 • 1回复 待解决