提供类似aar包内Activity之间跳转问题

1. SDK对外提供接口,启动接口会拉起SDK内部的页面。

2. SDK内部有多个页面,页面间有来回的跳转。

HarmonyOS
2024-02-20 15:03:11
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
richard_li_li
1

可以在har中使用命名路由( router.pushNamedRoute )来实现

示例代码

MainPage

@Entry({ routeName: 'MainPage' }) 
@Component 
export struct MainPage { 
  @State message: string = 'Hello World'; 
 
  build() { 
    Row() { 
      Column() { 
        Text(this.message) 
          .fontSize(30) 
          .fontWeight(FontWeight.Bold) 
          .backgroundColor(Color.Pink) 
        Text(JSON.stringify(router.getParams())) 
          .fontSize(30) 
          .fontWeight(FontWeight.Bold) 
          .backgroundColor(Color.Yellow) 
        Button('跳转第二个页面') 
          .onClick(() => { 
            router.pushNamedRoute({ 
              name: 'SecondPage' 
            }) 
          }) 
      } 
      .width('100%') 
    } 
    .height('100%') 
  } 
}
SecondPage
@Entry({ routeName: 'SecondPage' }) 
@Component 
export struct SecondPage { 
  @State message: string = 'SecondPage'; 
 
  build() { 
    Row() { 
      Column() { 
        Text(this.message) 
          .fontSize(50) 
          .fontWeight(FontWeight.Bold) 
          .backgroundColor(Color.Yellow) 
        Button('返回上一页router') 
          .onClick(() => { 
            console.log('返回上一页通过router') 
            router.pushNamedRoute({ 
              name: 'MainPage' 
            }) 
          }) 
        Button('返回上一页通过back') 
          .onClick(() => { 
            console.log('返回上一页通过back') 
            router.back() 
 
          }) 
      } 
      .width('100%') 
    } 
    .height('100%') 
  } 
}
class RouterParams { 
  private param1: string 
  private param2: number[] 
 
  constructor(param1: string, param2: number[]) { 
    this.param1 = param1 
    this.param2 = param2 
  } 
} 
 
export class Test { 
  static routerToAnother(message: string, arr: Array<number>) { 
    router.pushNamedRoute({ 
      name: 'MainPage', 
      params: new RouterParams(message, arr) 
    }) 
  } 
}

har中Index.ets

export { MainPage } from './src/main/ets/components/mainpage/MainPage'; 
export { Test } from './src/main/ets/components/mainpage/Test'; 
export {SecondPage}from'./src/main/ets/components/mainpage/SecondPage'

外部引用

@Entry 
@Component 
struct Index { 
  @State message: string = '使用接口方法'; 
 
  build() { 
    Row() { 
      Column() { 
        Button(this.message) 
          .fontSize(50) 
          .fontWeight(FontWeight.Bold) 
          .onClick(() => { 
            Test.routerToAnother('message', [1, 2.3]) 
          }) 
 
        Button('使用命名路由') 
          .fontSize(50) 
          .fontWeight(FontWeight.Bold) 
          .onClick(() => { 
            router.pushNamedRoute({ 
              name: 'MainPage' 
            }) 
          }) 
      } 
      .width('100%') 
    } 
    .height('100%') 
  } 
}
分享
微博
QQ
微信
回复
2024-02-20 20:11:50
相关问题
如何实现设备跨应用的UIAbility跳转
283浏览 • 1回复 待解决
页面之间跳转方式怎么设置的
4476浏览 • 1回复 待解决
Service 开启 Activity 失败
523浏览 • 1回复 待解决
应用跳转问题怎么处理?
3401浏览 • 1回复 待解决
关于Intent跳转桌面问题
5413浏览 • 1回复 待解决
如何跳转到共享中的指定页面
234浏览 • 1回复 待解决
JS跳转Java传参问题
3056浏览 • 1回复 待解决
header域值类型的问题有懂的吗?
338浏览 • 1回复 待解决
鸿蒙工程不支持aar本地导入吗?
6165浏览 • 1回复 已解决
跨模块路由跳转问题有知道的吗?
372浏览 • 1回复 待解决
聊一聊关于安装问题
7088浏览 • 2回复 待解决