HarmonyOS navigation是否支持模态嵌套路由

官方文档中说navigation支持模态嵌套路由,Navigation可以嵌套在模态对话框中,也就是说可以模态框中定义路由,是否有相关示例?

在Button属性bindContentCover(this.isShow, this.myBuilder())中模态一个页面,使用一个新的navigation后模态内容不显示。

关键代码如下:

@Entry
@Component
struct Index {
  pageInfo: NavPathStack = new NavPathStack()

  build() {
    Navigation(this.pageInfo) {
      Column() {
        Button('StartTest', { stateEffect: true, type: ButtonType.Capsule })
          .width('80%')
          .height(40)
          .margin(20)
          .onClick(() => {
            this.pageInfo.pushPath({ name: 'A2' }); // 将name指定的NavDestination页面信息入栈。
          })
      }
    }.title('NavIndex')
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
@Component
struct A2 {
  @State isShow: boolean = false
  pageStack: NavPathStack = new NavPathStack();

  @Builder
  myBuilder() {
    Navigation(this.pageStack) {
      Column() {
        Row() {
          Text('模态中嵌套的navigation页面')
            .fontSize(50)
            .fontWeight(FontWeight.Bold)
            .onClick(() => {
              this.pageStack.pushPathByName("A4", null, false);
            })
        }

        Text('dismiss')
          .width('80%')
          .height(40)
          .margin(20)
          .onClick(() => {
            this.isShow = false
          })
      }
      .justifyContent(FlexAlign.Center)
      .height('100%')
      .width('100%')
    }
    .hideNavBar(true)
  }

  build() {
    NavDestination() {
      Column() {
        Button('模态转场', { stateEffect: true, type: ButtonType.Capsule })
          .width('80%')
          .height(40)
          .margin(20)
          .bindContentCover(this.isShow, this.myBuilder())
          .onClick(() => {
            this.isShow = true;
          })
      }
      .width('100%')
      .height('100%')
    }
    .title('A2Page')
  }
}
  • 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.
HarmonyOS
2025-01-09 15:54:53
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
fox280

参考如下示例修改:

@Builder
myBuilder() {
  NavDestination() {
    Column() {
      Row() {
        Text('模态中嵌套的navigation页面')
          .fontSize(50)
          .fontWeight(FontWeight.Bold)
          .onClick(() => {
            this.pageStack.pushPathByName("Test240815164323062A4", null, false);
            // this.pageStack.pushPath({ name: 'Test240815164323062A4' }); // 将name指定的NavDestination页面信息入栈。
          })
      }

      Text('dismiss')
        .width('80%')
        .height(40)
        .margin(20)
        .onClick(() => {
          this.isShow = false
        })
    }
    .justifyContent(FlexAlign.Center)
    .height('100%')
    .width('100%')
  }
  // .hideNavBar(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.
  • 26.
  • 27.
  • 28.
分享
微博
QQ
微信
回复
2025-01-09 18:47:49
相关问题
HarmonyOS Navigation路由问题
744浏览 • 1回复 待解决
HarmonyOS RN是否支持CodePush与Navigation
815浏览 • 1回复 待解决
$r是否支持嵌套,有人知道吗?
1420浏览 • 1回复 待解决
路由导航用router还是navigation
333浏览 • 1回复 待解决
Navigation二级导航嵌套
2460浏览 • 1回复 待解决
Navigation实现动态路由的方式
1532浏览 • 1回复 待解决
HarmonyOS NEXT支持哪些路由模式?
265浏览 • 0回复 待解决
HarmonyOS 支持react-navigation了吗
616浏览 • 1回复 待解决