在同一个hap下,页面之间的跳转可以用命名路由的方式可见以下案例:在页面src/main/ets/pages/Index.ets中import router from '@ohos.router'; import { BusinessError } from '@ohos.base'; import('./myPage'); // 引入共享包中的命名路由页面 @Entry @Component struct Index { build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) { Text('Hello World') .fontSize(50) .fontWeight(FontWeight.Bold) .margin({ top: 20 }) .backgroundColor('#ccc') .onClick(() => { // 点击跳转到其他共享包中的页面 try { router.pushNamedRoute({ name: 'myPage', params: { data1: 'message', data2: { data3: [123, 456, 789] } } }) } catch (err) { let message = (err as BusinessError).message let code = (err as BusinessError).code console.error(`pushNamedRoute failed, code is ${code}, message is ${message}`); } }) } .width('100%') .height('100%') } } //在页面src/main/ets/pages/myPage.ets中 @Entry({ routeName: 'myPage' }) @Component export struct MyComponent { build() { Row() { Column() { Text('Library Page') .fontSize(50) .fontWeight(FontWeight.Bold) } .width('100%') } .height('100%') } }
在同一个hap下,页面之间的跳转可以用命名路由的方式
可见以下案例:
在页面src/main/ets/pages/Index.ets中