新建组件 Static Library
-
在 common 的 base 里添加二级路径
在 common 的 base 里添加二级路径 -
修改 Mine 组件里的路径
屏幕截图 2025-07-14 111806.png -
在 Mine 组件里添加 hmrouter_config.json 文件
给组件添加 HMRouter 在 Mine 组件里修改 hvigorfile.ts 的引入
import { harTasks } from '@ohos/hvigor-ohos-plugin';
import { harPlugin } from "@hadss/hmrouter-plugin";
export default {
system: harTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
plugins: [harPlugin()] /* Custom plugin to extend the functionality of Hvigor. */
}
在 Mine 组件里修改 hvigorfile.ts 的引入
- 在 Mine 组件里修改 oh-package.json5
{
"name": "mine",
"version": "1.0.0",
"description": "Please describe the basic information.",
"main": "Index.ets",
"author": "",
"license": "Apache-2.0",
"dependencies": {
'base':"file:../../common/base",
'components':"file:../../common/components",
"model": "file:../../common/model",
"utils": "file:../../common/utils",
"router": "file:../../common/router",
"image": "file:../../features/image",
"hmrouter": "file:../../features/hmrouter"
}
}
在 Mine 组件里修改 oh-package.json5
- 给二级页面添加路由
import { Pages } from "base";
import { HMRouter } from "router";
@HMRouter({pageUrl:Pages.MineErjiPage})
@ComponentV2
export struct MainPage {
@Local message: string = 'Hello World';
build() {
Row() {
Column() {
}
.width('100%')
}
.height('100%')
}
}
给二级页面添加路由
- 添加组件引入
最主要的一步
{
"name": "default",
"version": "1.0.0",
"description": "Please describe the basic information.",
"main": "",
"author": "",
"license": "",
"dependencies": {
...
"mine": "file:../../features/mine", // 引入
...
}
}
添加组件引入