HarmonyOS Navigation路由问题

在Index页面跳转PageOne页面的同时隐藏了导航页(hideNavBar),但是在PageOne页面返回上一页时,为什么会出现白屏的情况?

// Index.ets
@Entry
@Component
struct Index {
  @State hideNavBar: boolean = false
  private pageStack: NavPathStack = new NavPathStack()

  build() {
    Navigation(this.pageStack) {
      Column() {
        Button('跳转PageOne,隐藏NavBar')
          .onClick(() => {
            this.hideNavBar = true
            this.pageStack.replacePath({
              name: 'PageOne'
            })
          })
      }
      .height('100%')
      .justifyContent(FlexAlign.Center)
    }
    .hideNavBar(this.hideNavBar)
    .hideTitleBar(true)
    .hideBackButton(true)
  }
}


// PageOne.ets
@Builder
function PageOneBuilder() {
  PageOne()
}

@Component
export struct PageOne {
  pageStack: NavPathStack | null = null
  build() {
    NavDestination() {
      Column() {
        Button('返回上一页')
          .onClick(() => {
            // 这里返回上一页
            this.pageStack?.pop?.()
          })
      }.height('100%')
    }
    .hideTitleBar(true)
    .onReady((ctx: NavDestinationContext) => {
      this.pageStack = ctx.pathStack
    })
  }
}
  • 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.
HarmonyOS
2024-12-20 17:16:52
707浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
fox280

api介绍:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/arkts-navigation-navigation-V5

白屏的情况是隐藏了导航页Navigation导致 hideNavBar(true),设置为false回去就能看到上一个界面的导航页按钮。可以在Navigation上加一个button组件,在返回即使隐藏了Navigation也能看到button组件。具体使用再参考下api文档。

分享
微博
QQ
微信
回复
2024-12-20 20:07:34


相关问题
Navigation实现动态路由的方式
1500浏览 • 1回复 待解决
路由导航用router还是navigation
299浏览 • 1回复 待解决
HarmonyOS Navigation使用问题
1244浏览 • 1回复 待解决
HarmonyOS Navigation 使用问题
1167浏览 • 1回复 待解决
HarmonyOS 路由页面管理问题
848浏览 • 1回复 待解决
HarmonyOS 路由栈相关问题
888浏览 • 1回复 待解决
HarmonyOS关于navigation问题
1457浏览 • 1回复 待解决
HarmonyOS 路由返回页面问题
1013浏览 • 0回复 待解决
HarmonyOS router路由跳转问题
1429浏览 • 0回复 待解决
HarmonyOS 路由及导航问题
897浏览 • 1回复 待解决