HarmonyOS Navigation跳转、Tab切换重新加载问题

1、A和B两个页面都用Navigation做根布局,从A页面跳转到B页面使用NavPathStack做跳转页面没有正常显示。

2、B页面是个主页有三个Tab,在Tab切换时已经加载过的页面还会重新加载。

import router from '@ohos.router'

@Entry()
@Component
struct Index {
  @State message: string = 'Hello World'
  pageStack: NavPathStack = new NavPathStack();

  build() {
    Navigation(this.pageStack){

      Column(){
        Text('欢迎页')
          .margin({top: 120})
          .onClick(() => {
            //使用router跳转时正常显示
            router.pushUrl({url: "pages/MainPage"})
            //使用Navigation跳转时不能正常显示
            // this.pageStack.pushPathByName("MainPage", null)
          })
      }

    }.hideTitleBar(true)
  }
}
  • 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.
HarmonyOS
2024-12-25 12:04:59
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
Heiang

Index页面中若要使用Navigation进行路由导航,需要在index页面中配置路由map,如:

@Builder
PageMap(pageName: string) {
  if (pageName === 'MainPage') {
    MainPage()
  }
}
......
Navigation(this.pageStack){

  Column(){
    Text('欢迎页')
      .margin({top: 120})
      .onClick(() => {
        //使用router跳转时正常显示
        // router.pushUrl({url: "pages/MainPage"})
        //使用Navigation跳转时不能正常显示
        this.pageStack.pushPathByName("MainPage", null)
      })
  }

}.hideTitleBar(true)
.navDestination(this.PageMap)
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.

MainPage中是通过Navigation进行路由跳转切换页面的,建议使用Tabs切换加载页面:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-container-tabs-V5

分享
微博
QQ
微信
回复
2024-12-25 15:37:37
相关问题
HarmonyOS NavigationTab组件问题
2109浏览 • 1回复 待解决
Tab控件切换问题有哪些?
1214浏览 • 1回复 待解决
HarmonyOS tab切换demo
652浏览 • 1回复 待解决
HarmonyOS Navigation动态跳转页面问题
840浏览 • 1回复 待解决
Navigation页面跳转问题
1373浏览 • 1回复 待解决
Tab组件内嵌web view左右滑动切换问题
1096浏览 • 1回复 待解决
HarmonyOS router跳转navigation跳转
799浏览 • 1回复 待解决
HarmonyOS Tab居中问题
624浏览 • 1回复 待解决
HarmonyOS navigation跳转参数获取
632浏览 • 1回复 待解决
HarmonyOS 100005 Navigation跳转失败
578浏览 • 1回复 待解决
HarmonyOS 怎么让整个Page重新加载
698浏览 • 1回复 待解决
Navigation实现Tabs切换效果
2056浏览 • 1回复 待解决
Tab组件问题
724浏览 • 1回复 待解决