有什么动态页面跳转的方案?

目前的跳转方式比如router,目前必须要提前配置好页面进行跳转,但是应用的小程序都是不确定的, 需要做到运行时动态配置页面。有没有可行的实现方案。

阅读 196
1 个回答

可以在跳转之前,获取到实际要跳转的页面路径,然后替换掉路径。

参考代码:

import router from '@ohos.router'; 
@Entry 
@Component 
struct Index { 
  @State message: string = 'A页面'; 
  @State urlString :string='pages/Index02'//原本要跳转的页面B 
 
  build() { 
    Row() { 
      Column() { 
        Text(this.message) 
          .fontSize(50) 
          .fontWeight(FontWeight.Bold) 
        Button('点我跳转B') 
          .onClick(()=>{ 
            //在跳转之前获取到实际要跳转的页面C 
            this.urlString='pages/Index03' 
            router.pushUrl({url:this.urlString}) 
          }) 
      } 
      .width('100%') 
    } 
    // .backgroundColor(Color.Red) 
    .height('100%') 
  } 
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进