16e7c69efSopenharmony_ci# Navigation系统路由 26e7c69efSopenharmony_ci 36e7c69efSopenharmony_ci### 介绍 46e7c69efSopenharmony_ci 56e7c69efSopenharmony_ci本项目提供系统路由的验证,运用系统路由表的方式,跳转到模块(HSP/HAR)的页面,可以不用配置不同跳转模块间的依赖。当发生页面跳转时,未跳转页面不会加载, 66e7c69efSopenharmony_ci已经加载过的页面不会再次加载。 解决了不同模块依赖耦合的问题,以及首页加载时间长的问题。 76e7c69efSopenharmony_ci详细配置可参考[系统路由表](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/ui/arkts-navigation-navigation.md)。 86e7c69efSopenharmony_ci 96e7c69efSopenharmony_ci由于环境的差异,不建议下载后直接编译,应先当创建项目,参考示例代码进行编写。 106e7c69efSopenharmony_ci 116e7c69efSopenharmony_ci### 效果预览 126e7c69efSopenharmony_ci 136e7c69efSopenharmony_ci<img src="./images/NavIndex.jpeg" width="200" height="360" /> 146e7c69efSopenharmony_ci 156e7c69efSopenharmony_ci| EntryPageOne | EntryPageTwo | HarAPageOne | 166e7c69efSopenharmony_ci|------------------------------------------------------------------|------------------------------------------------------------------|-----------------------------------------------------------------| 176e7c69efSopenharmony_ci| <img src="./images/EntryPageOne.jpeg" width="200" height="360"/> | <img src="./images/EntryPageTwo.jpeg" width="200" height="360"/> | <img src="./images/HarAPageOne.jpeg" width="200" height="360"/> | 186e7c69efSopenharmony_ci| HarAPageTwo | HspAPageOne | HspAPageTwo | 196e7c69efSopenharmony_ci| <img src="./images/HarAPageTwo.jpeg" width="200" height="360"/> | <img src="./images/HspAPageOne.jpeg" width="200" height="360"/> | <img src="./images/HspAPageTwo.jpeg" width="200" height="360"/> | 206e7c69efSopenharmony_ci 216e7c69efSopenharmony_ci使用说明 226e7c69efSopenharmony_ci 236e7c69efSopenharmony_ci1. 主页会提供一个NavIndex的导航页,点击按钮会跳转到不同的来自HAR和HSP包的页面 246e7c69efSopenharmony_ci 256e7c69efSopenharmony_ci2. 每个HAR和HSP包的页面也存在跳转到别的页面的按钮 266e7c69efSopenharmony_ci 276e7c69efSopenharmony_ci### 工程目录 286e7c69efSopenharmony_ci 296e7c69efSopenharmony_ci``` 306e7c69efSopenharmony_ci├──entry/src/main/ets/ 316e7c69efSopenharmony_ci│ ├──common 326e7c69efSopenharmony_ci│ │ └──utils 336e7c69efSopenharmony_ci│ │ └──Logger.ets // 日志打印封装 346e7c69efSopenharmony_ci│ ├──entryability 356e7c69efSopenharmony_ci│ │ └──EntryAbility.ets // 程序入口 366e7c69efSopenharmony_ci│ └──pages 376e7c69efSopenharmony_ci│ ├──EntryPageOne.ets // 页面1 386e7c69efSopenharmony_ci│ ├──EntryPageTwo.ets // 页面2 396e7c69efSopenharmony_ci│ └──Index.ets // 界面实现 406e7c69efSopenharmony_ci├──entry/src/main/resources // 应用资源目录 416e7c69efSopenharmony_ci├──harA 426e7c69efSopenharmony_ci├──harB 436e7c69efSopenharmony_ci├──hspA 446e7c69efSopenharmony_ci└──hspB 456e7c69efSopenharmony_ci``` 466e7c69efSopenharmony_ci 476e7c69efSopenharmony_ci### 具体实现 486e7c69efSopenharmony_ci 496e7c69efSopenharmony_ci1.创建hapA harA hspA hspB 506e7c69efSopenharmony_ci 516e7c69efSopenharmony_ci2.在跳转目标模块的配置文件[module.json5](entry/src/main/module.json5)添加路由表配置 526e7c69efSopenharmony_ci 536e7c69efSopenharmony_ci3.添加完路由配置文件地址后,需要在工程resources/base/profile中创建[route_map.json](entry/src/main/resources/base/profile/router_map.json) 546e7c69efSopenharmony_ci文件 556e7c69efSopenharmony_ci 566e7c69efSopenharmony_ci4.在跳转目标页面中,需要配置入口Builder函数,函数名称需要和[route_map.json](entry/src/main/resources/base/profile/router_map.json) 576e7c69efSopenharmony_ci配置文件中的buildFunction保持一致。 586e7c69efSopenharmony_ci 596e7c69efSopenharmony_ci5.应用通过调用pushDestinationByName等方式,可以获取跳转目标页面的错误信息。 606e7c69efSopenharmony_ci 616e7c69efSopenharmony_ci6.运行时需设置引用所有HSP模块。设置运行后,点击Run > entry来启动应用/服务的编译构建。 626e7c69efSopenharmony_ci 636e7c69efSopenharmony_ci### 相关权限 646e7c69efSopenharmony_ci 656e7c69efSopenharmony_ci不涉及 666e7c69efSopenharmony_ci 676e7c69efSopenharmony_ci### 依赖 686e7c69efSopenharmony_ci 696e7c69efSopenharmony_ci不涉及。 706e7c69efSopenharmony_ci 716e7c69efSopenharmony_ci### 约束与限制 726e7c69efSopenharmony_ci 736e7c69efSopenharmony_ci1. 本示例仅支持标准系统上运行,支持设备:RK3568。 746e7c69efSopenharmony_ci 756e7c69efSopenharmony_ci2. 本示例仅支持API12版本SDK,版本号:5.0.0.26,镜像版本号:OpenHarmony 5.0.0.26。 766e7c69efSopenharmony_ci 776e7c69efSopenharmony_ci3. 本示例需要使用DevEco Studio NEXT Developer Beta5 (Build Version: 5.0.3.700)才可编译运行; 786e7c69efSopenharmony_ci 796e7c69efSopenharmony_ci### 下载 806e7c69efSopenharmony_ci 816e7c69efSopenharmony_ci如需单独下载本工程,执行如下命令: 826e7c69efSopenharmony_ci 836e7c69efSopenharmony_ci``` 846e7c69efSopenharmony_cigit init 856e7c69efSopenharmony_cigit config core.sparsecheckout true 866e7c69efSopenharmony_ciecho code/BasicFeature/ApplicationModels/SystemRouter > .git/info/sparse-checkout 876e7c69efSopenharmony_cigit remote add origin https://gitee.com/openharmony/applications_app_samples.git 886e7c69efSopenharmony_cigit pull origin master 896e7c69efSopenharmony_ci``` 90