跨module跳转具体可使用NavPushPathHelper即可实现。// PageOne.ets import { NavPushPathHelper } from '@kit.ArkUI' import { BusinessError } from '@kit.BasicServicesKit'; class TmpClass { count: number = 10 } class ParamWithOp { operation: number = 1 count: number = 10 } @Builder export function PageOneBuilder(name: string, param: Object) { PageOne() } @Component export struct PageOne { pageInfo: NavPathStack = new NavPathStack(); helper: NavPushPathHelper = new NavPushPathHelper(this.pageInfo) @State message: string = 'Hello World' build() { NavDestination() { Column() { Text(this.message) .width('80%') .height(50) .margin(10) Button('pushPath', { stateEffect: true, type: ButtonType.Capsule }) .width('80%') .height(35) .margin(10) .onClick(() => { this.helper.pushPath('hsptest2', { name: 'pageTwo', param: new ParamWithOp(), onPop: (popInfo: PopInfo) => { this.message = '[pushPath]last page is: ' + popInfo.info.name + ', result: ' + JSON.stringify(popInfo.result); }}).catch((error: BusinessError) => { console.error(`[pushPath]failed, error code = ${error.code}, error.message = ${error.message}.`); }).then(() => { console.log('[pushPath]success.'); }); }) Button('replacePathByName', { stateEffect: true, type: ButtonType.Capsule }) .width('80%') .height(35) .margin(10) .onClick(() => { let tmp = new TmpClass() this.helper.replacePathByName('hsptest2', 'pageTwo', tmp) .catch((error: BusinessError) => { console.error(`[replacePathByName]failed, error code = ${error.code}, error.message = ${error.message}.`); }).then(() => { console.log('[replacePathByName]success.'); }); }) }.width('100%').height('100%') }.title('pageOne') .onBackPressed(() => { this.pageInfo.pop({ number: 1 }) // 弹出路由栈栈顶元素。 return true }).onReady((context: NavDestinationContext) => { this.pageInfo = context.pathStack; this.helper = new NavPushPathHelper(this.pageInfo); }) } }
跨module跳转具体可使用NavPushPathHelper即可实现。