检查中转页跳转至二级页面的逻辑是否具备幂等性(幂等性是指接口可重复调用,在调用方多次调用的情况下,接口最终得到的结果是一致的)或跳转标记,避免在返回时重复触发跳转。
再根据日志及录屏分析,(日志打印can't find inner navigation,录屏返回时跳转到中转页。)用户在搜索了某个关键词后点入了一个二级页面并进行右滑返回,而该二级页面通过中转页跳转,致使右滑返回到了中转页触发了跳转逻辑又跳转回了二级页面。对照实验直接搜索一级页面或者无需跳转的二级页面则未触发此问题。
@Component
struct LaunchPage {
pageStack: NavPathStack = new NavPathStack();
@State hasRedirected: boolean = false;
build() {
Navigation(this.pageStack) {
Column() {
Text('中转页,准备跳转...')
}
}
.onAppear(() => {
// 自动跳转,仅执行一次
if (!this.hasRedirected) {
this.hasRedirected = true;
this.pageStack.pushPathByName('TargetPage',null);
}
})
}
} @Component
struct TargetPage {
@State pageStack: NavPathStack = new NavPathStack();
build() {
NavDestination() {
Column() {
Text('目标页')
.fontSize(24)
.margin(20)
}
}
.onReady((ctx: NavDestinationContext) => {
this.pageStack = ctx.pathStack;
})
}
} @Entry
struct LaunchPageAndTargetPage{
build() {
Column() {
LaunchPage()
TargetPage()
}
}
}