路由跳转到只有一个UIAbility的模块:
- 现在有A,B两个页面。只有一个UIAbility,整个App只想使用一个UIAbility的情况下,A页面跳转到B页面并且带参数。
案例
- 项目/entry/src/main/resources/base/profile/main_pages.json
{
"src": [
"pages/Index",
"pages/SubPag" // 添加页面
]
}
- Index.ets
import { router } from '@kit.ArkUI'
@Entry
@Component
struct Index {
build(){
Button('点击跳转页面').onClick((event: ClickEvent) => {
router.pushUrl({
url: 'pages/SubPag',
params: {
userName: 'zs'
}
})
})
}
}
- SubPag.ets
import { router } from '@kit.ArkUI';
interface UserVO {
userName: string;
}
@Entry
@Component
struct SubPag {
@State message: string = 'Hello World';
aboutToAppear(): void {
let params = router.getParams() as UserVO;
console.log('params参数 === ', JSON.stringify(params));
}
build() {
Text('hello')
}
}