赞
踩
router.pushNamedRoute / router.pushUrl / HSP
通过router.pushNamedRoute在主工程页面跳转到其他模块后,其他模块的页面使用router.pushUrl跳转方法失效,存在子模块与主模块跳转无法同时兼容的问题。
直接启动Testapplication子模块可以跳转,pushUrl方法正常,从主入口通过以下方式进入,pushUrl跳转无效。
具体示例代码如下:
- 主模块Index页面代码:
- import ('@BOB/Testapplication/src/main/ets/pages/album')
- import router from '@ohos.router';
- //执行该方法跳转到子模块'album'页面
- router.pushNamedRoute({
- name: 'album', //入口名称
- })
-
-
- Testapplication子模块album页面代码:
- import router from '@ohos.router';
-
- @Entry ({ routeName : 'album' })
- @Component
- struct ablum {
- @State message: string = 'Hi album'
- build() {
- Row() {
- Column() {
- Text(this.message)
- .fontSize(50)
- .fontWeight(FontWeight.Bold)
- Button("pushUrl跳转albumFirst",{ type: ButtonType.Normal, stateEffect: true })
- .borderRadius(8)
- .backgroundColor(0x317aff)
- .width(150)
- .height(60)
- .margin(20)
- .onClick(()=>{
- router.pushUrl({
- url: 'pages/albumFirst',
- // params: new routerParams(this.pageName ,[])
- })//默认模式
- })
-
- .width('100%')
- // .alignItems(HorizontalAlign.Center)
- // .justifyContent(FlexAlign.Start)
- }
- }
- .height('100%')
- }

当跳转的目标页面属于HSP时(包括HSP页面跳HSP页面),需要使用特定写法。
也可以使用路由命名的形式实现,@bundle的方面只支持跳转hsp页面,路由命名支持跳转到HAP、HSP、HAR的页面。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。