可以在跳转之前,获取到实际要跳转的页面路径,然后替换掉路径。参考代码: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%') } }
可以在跳转之前,获取到实际要跳转的页面路径,然后替换掉路径。
参考代码: