HarmonyOS 鸿蒙Next ArkTs页面跳转
HarmonyOS 鸿蒙Next ArkTs页面跳转 建了一个text的点击事件,页面跳转没反应,请教,谢谢
更多关于HarmonyOS 鸿蒙Next ArkTs页面跳转的实战教程也可以访问 https://www.itying.com/category-93-b0.html
TypePage页面,你创建时,是选择ArkTS File, 还是选择Page的,如果是选择ArkTS File, 你要手工在resources -> profile 目录下main_pages.sjon文件里添加"pages/TypePage" ,如果是选择Page,工具会自动在main_pages.json文件配置添加。
更多关于HarmonyOS 鸿蒙Next ArkTs页面跳转的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
要配置路由,不然router读不到
在resources>profile的main_pages.json中配置页面路由
是的,是选择ArkTS File创建的Page,没在Profile加,现在加上好了,感谢
在HarmonyOS中,使用ArkTS进行页面跳转主要通过router
模块实现。首先,需要在entry/src/main/ets/pages
目录下定义目标页面,并在entry/src/main/resources/base/profile
中配置路由信息。例如,定义Index
和Detail
两个页面:
// Index.ets
import router from '@ohos.router';
@Entry
@Component
struct Index {
build() {
Column() {
Button('跳转到详情页')
.onClick(() => {
router.pushUrl({
url: 'pages/Detail'
});
});
}
}
}
// Detail.ets
@Entry
@Component
struct Detail {
build() {
Column() {
Text('这是详情页');
}
}
}
在entry/src/main/resources/base/profile/main_pages.json
中配置路由:
{
"src": [
"pages/Index",
"pages/Detail"
]
}
通过router.pushUrl
方法实现从Index
页面跳转到Detail
页面。如果需要返回上一页,可以使用router.back
方法。