目录
路由介绍
使用示例
在跳转目标模块的配置文件module.json5添加路由表配置:
{
"module" : {
"routerMap": "$profile:route_map"
}
}
路由映射表的路径
ohos/entry/src/main/resources/base/profile/route_map.json
路由映射关系
{
"routerMap": [
{
"name": "/modules/foundersc/about",
"pageSourceFile": "src/main/ets/pages/AboutPage.ets",
"buildFunction": "getAboutPage",
"data": {
}
},
{
"name": "/modules/foundersc/elecCard",
"pageSourceFile": "src/main/ets/pages/eleccard/ElecCardPage.ets",
"buildFunction": "getElecCardPage",
"data": {
}
}
]
}
路由到页面的代码
import { TitleBar } from '../../webContainer/pages/TitleBar'
import App from '@system.app'
@Entry
@Component
export struct ElecCardPage {
build() {
// 需要 NavDestination包裹
NavDestination(){
Column(){
TitleBar({
title: "电子名片",
bottomLineVisibility: false
})
}
}
.hideTitleBar(true)
.width('100%').height('100%')
}
}
// 需要提供路由表内指定的方法
@Builder
export function getElecCardPage() {
ElecCardPage();
}
路由跳转
DfRouter.pushUrl(url1, params, title, from);
行者常至,为者常成!