diff --git a/zh-cn/application-dev/quick-start/atomicService.md b/zh-cn/application-dev/quick-start/atomicService.md index d99306b2a37028f0c1e3c27269f17c614cd3df36..d5b5fa137a24db7358cefb0aaea329527572d11a 100644 --- a/zh-cn/application-dev/quick-start/atomicService.md +++ b/zh-cn/application-dev/quick-start/atomicService.md @@ -200,11 +200,12 @@ struct Index { }).catch(err => { console.error(`pushUrl failed, code is ${err.code}, message is ${err.message}`); }) - } - .width('100%') + }) + .width('100%') } .height('100%') } + } } ``` diff --git a/zh-cn/application-dev/quick-start/in-app-hsp.md b/zh-cn/application-dev/quick-start/in-app-hsp.md index 0cd31484efcafe7e7512efbb6f3fc2718cee6b5e..46a95e3c365fb7b4ca34b11e49917c55ac0afb83 100644 --- a/zh-cn/application-dev/quick-start/in-app-hsp.md +++ b/zh-cn/application-dev/quick-start/in-app-hsp.md @@ -150,4 +150,60 @@ struct Index { .height('100%') } } +``` + +### 跨包页面路由跳转 + +若开发者想在entry模块中,添加一个按钮跳转至library模块中的menu页面(路径为:`library/src/main/ets/pages/menu.ets`),那么可以在使用方的代码(entry模块下的Index.ets,路径为:`entry/src/main/ets/MainAbility/Index.ets`)里这样使用: +```ts +import router from '@ohos.router'; + +@Entry +@Component +struct Index { + @State message: string = 'Hello World' + + build() { + Row() { + Column() { + Text(this.message) + .fontSize(50) + .fontWeight(FontWeight.Bold) + // 添加按钮,以响应用户点击 + Button() { + Text('click to menu') + .fontSize(30) + .fontWeight(FontWeight.Bold) + } + .type(ButtonType.Capsule) + .margin({ + top: 20 + }) + .backgroundColor('#0D9FFB') + .width('40%') + .height('5%') + // 绑定点击事件 + .onClick(() => { + router.pushUrl({ + url: '@bundle:com.example.hmservice/library/ets/pages/menu' + }).then(() => { + console.log("push page success"); + }).catch(err => { + console.error(`pushUrl failed, code is ${err.code}, message is ${err.message}`); + }) + }) + .width('100%') + } + .height('100%') + } + } +} +``` +其中`router.pushUrl`方法的入参中`url`的内容为: +```ets +'@bundle:com.example.hmservice/library/ets/pages/menu' +``` +`url`内容的模板为: +```ets +'@bundle:包名(bundleName)/模块名(moduleName)/路径/页面所在的文件名(不加.ets后缀)' ``` \ No newline at end of file