1e41f4b71Sopenharmony_ci# NavPushPathHelper 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci当跳转的目标[NavDestination](ts-basic-components-navdestination.md)在不同的hsp分包,且未被主包依赖,首次运行元服务只会下载安装主包,需要使用NavPushPathHelper先下载安装相应hsp分包,再将指定的[NavDestination](ts-basic-components-navdestination.md)页面信息入栈。使[Navigation](ts-basic-components-navigation.md)支持动态加载hsp分包后再跳转。 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **说明:** 6e41f4b71Sopenharmony_ci> 7e41f4b71Sopenharmony_ci> 该组件从API Version 12开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci## 导入模块 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci```ts 12e41f4b71Sopenharmony_ciimport { NavPushPathHelper } from '@kit.ArkUI' 13e41f4b71Sopenharmony_ci``` 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci## 子组件 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci无 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ci## 属性 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci不支持[通用属性](ts-universal-attributes-size.md) 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci## NavPushPathHelper 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci对Navigation路由栈[NavPathStack](ts-basic-components-navigation.md#navpathstack10)的所有路由跳转接口进行了封装,在NavPushPathHelper中持有一个NavPathStack对象,在封装的跳转接口中,去判断子包是否存在,如果不存在则进行动态下载子包,等结果返回后调用NavPathStack的相应的接口将指定的[NavDestination](ts-basic-components-navdestination.md)页面信息入栈。使用示例参见[示例](#示例)。 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci### constructor 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ciconstructor(navPathStack: NavPathStack): void 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ciNavPushPathHelper的构造函数。 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci**参数:** 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 描述 | 40e41f4b71Sopenharmony_ci| ---- | ----------------------------- | ---- | -------------------- | 41e41f4b71Sopenharmony_ci| navPathStack | [NavPathStack](ts-basic-components-navigation.md#navpathstack10) | 是 | [Navigation](ts-basic-components-navigation.md)路由栈。 | 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci### pushPath 44e41f4b71Sopenharmony_ci 45e41f4b71Sopenharmony_cipushPath(moduleName: string, info: NavPathInfo, animated?: boolean): Promise\<void\> 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_ci先判断分包是否存在,若不存在,则通过moduleName下载分包,再将info指定的[NavDestination](ts-basic-components-navdestination.md)页面信息入栈,使用Promise异步回调返回接口调用结果。 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 52e41f4b71Sopenharmony_ci 53e41f4b71Sopenharmony_ci**参数:** 54e41f4b71Sopenharmony_ci 55e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 描述 | 56e41f4b71Sopenharmony_ci| ---- | ----------------------------- | ---- | -------------------- | 57e41f4b71Sopenharmony_ci| moduleName | string | 是 | 目标[NavDestination](ts-basic-components-navdestination.md)所在分包的moduleName。 | 58e41f4b71Sopenharmony_ci| info | [NavPathInfo](ts-basic-components-navigation.md#navpathinfo10) | 是 | [NavDestination](ts-basic-components-navdestination.md)页面的信息。 | 59e41f4b71Sopenharmony_ci| animated | boolean | 否 | 是否支持转场动画,默认值:true。 | 60e41f4b71Sopenharmony_ci 61e41f4b71Sopenharmony_ci**返回值:** 62e41f4b71Sopenharmony_ci 63e41f4b71Sopenharmony_ci| 类型 | 说明 | 64e41f4b71Sopenharmony_ci| ------------------- | --------- | 65e41f4b71Sopenharmony_ci| Promise\<void\> | 异常返回结果。 | 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_ci**错误码:** 68e41f4b71Sopenharmony_ci 69e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[ohos.router(页面路由)](../errorcode-router.md)错误码。 70e41f4b71Sopenharmony_ci 71e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 72e41f4b71Sopenharmony_ci| --------- | ------- | 73e41f4b71Sopenharmony_ci| 300001 | hsp silent install fail.| 74e41f4b71Sopenharmony_ci 75e41f4b71Sopenharmony_ci### pushPath 76e41f4b71Sopenharmony_ci 77e41f4b71Sopenharmony_cipushPath(moduleName: string, info: NavPathInfo, options?: NavigationOptions): Promise\<void\> 78e41f4b71Sopenharmony_ci 79e41f4b71Sopenharmony_ci先判断分包是否存在,若不存在,则通过moduleName下载分包,再将info指定的[NavDestination](ts-basic-components-navdestination.md)页面信息入栈,使用Promise异步回调返回接口调用结果,具体根据options中指定不同的[LaunchMode](ts-basic-components-navigation.md#launchmode12枚举说明),有不同的行为。 80e41f4b71Sopenharmony_ci 81e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ci**参数:** 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 描述 | 88e41f4b71Sopenharmony_ci| ---- | ----------------------------- | ---- | -------------------- | 89e41f4b71Sopenharmony_ci| moduleName | string | 是 | 目标[NavDestination](ts-basic-components-navdestination.md)所在分包的moduleName。 | 90e41f4b71Sopenharmony_ci| info | [NavPathInfo](ts-basic-components-navigation.md#navpathinfo10) | 是 | [NavDestination](ts-basic-components-navdestination.md)页面的信息。 | 91e41f4b71Sopenharmony_ci| options | [NavigationOptions](ts-basic-components-navigation.md#navigationoptions12) | 否 | 页面栈操作选项。 | 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_ci**返回值:** 94e41f4b71Sopenharmony_ci 95e41f4b71Sopenharmony_ci| 类型 | 说明 | 96e41f4b71Sopenharmony_ci| ------------------- | --------- | 97e41f4b71Sopenharmony_ci| Promise\<void\> | 异常返回结果。 | 98e41f4b71Sopenharmony_ci 99e41f4b71Sopenharmony_ci**错误码:** 100e41f4b71Sopenharmony_ci 101e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[ohos.router(页面路由)](../errorcode-router.md)错误码。 102e41f4b71Sopenharmony_ci 103e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 104e41f4b71Sopenharmony_ci| --------- | ------- | 105e41f4b71Sopenharmony_ci| 300001 | hsp silent install fail.| 106e41f4b71Sopenharmony_ci 107e41f4b71Sopenharmony_ci### pushPathByName 108e41f4b71Sopenharmony_ci 109e41f4b71Sopenharmony_cipushPathByName(moduleName: string, name: string, param: Object, animated?: boolean): Promise\<void\> 110e41f4b71Sopenharmony_ci 111e41f4b71Sopenharmony_ci先判断分包是否存在,若不存在,则通过moduleName下载分包,再将name指定的[NavDestination](ts-basic-components-navdestination.md)页面信息入栈,传递的数据为param,使用Promise异步回调返回接口调用结果。 112e41f4b71Sopenharmony_ci 113e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 114e41f4b71Sopenharmony_ci 115e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 116e41f4b71Sopenharmony_ci 117e41f4b71Sopenharmony_ci**参数:** 118e41f4b71Sopenharmony_ci 119e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 描述 | 120e41f4b71Sopenharmony_ci| ----- | ------- | ---- | --------------------- | 121e41f4b71Sopenharmony_ci| moduleName | string | 是 | 目标[NavDestination](ts-basic-components-navdestination.md)所在分包的moduleName。 | 122e41f4b71Sopenharmony_ci| name | string | 是 | [NavDestination](ts-basic-components-navdestination.md)页面名称。 | 123e41f4b71Sopenharmony_ci| param | Object | 是 | [NavDestination](ts-basic-components-navdestination.md)页面详细参数。 | 124e41f4b71Sopenharmony_ci| animated | boolean | 否 | 是否支持转场动画,默认值:true。 | 125e41f4b71Sopenharmony_ci 126e41f4b71Sopenharmony_ci**返回值:** 127e41f4b71Sopenharmony_ci 128e41f4b71Sopenharmony_ci| 类型 | 说明 | 129e41f4b71Sopenharmony_ci| ------------------- | --------- | 130e41f4b71Sopenharmony_ci| Promise\<void\> | 异常返回结果。 | 131e41f4b71Sopenharmony_ci 132e41f4b71Sopenharmony_ci**错误码:** 133e41f4b71Sopenharmony_ci 134e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[ohos.router(页面路由)](../errorcode-router.md)错误码。 135e41f4b71Sopenharmony_ci 136e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 137e41f4b71Sopenharmony_ci| --------- | ------- | 138e41f4b71Sopenharmony_ci| 300001 | hsp silent install fail.| 139e41f4b71Sopenharmony_ci 140e41f4b71Sopenharmony_ci### pushPathByName 141e41f4b71Sopenharmony_ci 142e41f4b71Sopenharmony_cipushPathByName(moduleName: string, name: string, param: Object, onPop: Callback\<PopInfo>, animated?: boolean): Promise\<void\> 143e41f4b71Sopenharmony_ci 144e41f4b71Sopenharmony_ci先判断分包是否存在,若不存在,则通过moduleName下载分包,再将name指定的[NavDestination](ts-basic-components-navdestination.md)页面信息入栈,传递的数据为param,添加onPop回调接收入栈页面出栈时的返回结果,并进行处理,使用Promise异步回调返回接口调用结果。 145e41f4b71Sopenharmony_ci 146e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 147e41f4b71Sopenharmony_ci 148e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 149e41f4b71Sopenharmony_ci 150e41f4b71Sopenharmony_ci**参数:** 151e41f4b71Sopenharmony_ci 152e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 描述 | 153e41f4b71Sopenharmony_ci|------|------|------|------| 154e41f4b71Sopenharmony_ci| moduleName | string | 是 | 目标[NavDestination](ts-basic-components-navdestination.md)所在分包的moduleName。 | 155e41f4b71Sopenharmony_ci| name | string | 是 | [NavDestination](ts-basic-components-navdestination.md)页面名称。 | 156e41f4b71Sopenharmony_ci| param | Object | 是 | [NavDestination](ts-basic-components-navdestination.md)页面详细参数。 | 157e41f4b71Sopenharmony_ci| onPop | Callback\<[PopInfo](ts-basic-components-navigation.md#popinfo11)> | 是 | Callback回调,用于页面出栈时触发该回调处理返回结果。 | 158e41f4b71Sopenharmony_ci| animated | boolean | 否 | 是否支持转场动画,默认值:true。 | 159e41f4b71Sopenharmony_ci 160e41f4b71Sopenharmony_ci**返回值:** 161e41f4b71Sopenharmony_ci 162e41f4b71Sopenharmony_ci| 类型 | 说明 | 163e41f4b71Sopenharmony_ci| ------------------- | --------- | 164e41f4b71Sopenharmony_ci| Promise\<void\> | 异常返回结果。 | 165e41f4b71Sopenharmony_ci 166e41f4b71Sopenharmony_ci**错误码:** 167e41f4b71Sopenharmony_ci 168e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[ohos.router(页面路由)](../errorcode-router.md)错误码。 169e41f4b71Sopenharmony_ci 170e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 171e41f4b71Sopenharmony_ci| --------- | ------- | 172e41f4b71Sopenharmony_ci| 300001 | hsp silent install fail.| 173e41f4b71Sopenharmony_ci 174e41f4b71Sopenharmony_ci### pushDestination 175e41f4b71Sopenharmony_ci 176e41f4b71Sopenharmony_cipushDestination(moduleName: string, info: NavPathInfo, animated?: boolean): Promise\<void\> 177e41f4b71Sopenharmony_ci 178e41f4b71Sopenharmony_ci先判断分包是否存在,若不存在,则通过moduleName下载分包,再将info指定的[NavDestination](ts-basic-components-navdestination.md)页面信息入栈,使用Promise异步回调返回接口调用结果。 179e41f4b71Sopenharmony_ci 180e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 181e41f4b71Sopenharmony_ci 182e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 183e41f4b71Sopenharmony_ci 184e41f4b71Sopenharmony_ci**参数:** 185e41f4b71Sopenharmony_ci 186e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 描述 | 187e41f4b71Sopenharmony_ci| ---- | ----------------------------- | ---- | -------------------- | 188e41f4b71Sopenharmony_ci| moduleName | string | 是 | 目标[NavDestination](ts-basic-components-navdestination.md)所在分包的moduleName。 | 189e41f4b71Sopenharmony_ci| info | [NavPathInfo](ts-basic-components-navigation.md#navpathinfo10) | 是 | [NavDestination](ts-basic-components-navdestination.md)页面的信息。 | 190e41f4b71Sopenharmony_ci| animated | boolean | 否 | 是否支持转场动画,默认值:true。 | 191e41f4b71Sopenharmony_ci 192e41f4b71Sopenharmony_ci**返回值:** 193e41f4b71Sopenharmony_ci 194e41f4b71Sopenharmony_ci| 类型 | 说明 | 195e41f4b71Sopenharmony_ci| ------------------- | --------- | 196e41f4b71Sopenharmony_ci| Promise\<void\> | 异常返回结果。 | 197e41f4b71Sopenharmony_ci 198e41f4b71Sopenharmony_ci**错误码:** 199e41f4b71Sopenharmony_ci 200e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../../errorcode-universal.md)和[ohos.router(页面路由)](../errorcode-router.md)错误码。 201e41f4b71Sopenharmony_ci 202e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 203e41f4b71Sopenharmony_ci| --------- | ------- | 204e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed. | 205e41f4b71Sopenharmony_ci| 100001 | Internal error.| 206e41f4b71Sopenharmony_ci| 100005 | Builder function not registered. | 207e41f4b71Sopenharmony_ci| 100006 | NavDestination not found.| 208e41f4b71Sopenharmony_ci| 300001 | hsp silent install fail.| 209e41f4b71Sopenharmony_ci 210e41f4b71Sopenharmony_ci### pushDestination 211e41f4b71Sopenharmony_ci 212e41f4b71Sopenharmony_cipushDestination(moduleName: string, info: NavPathInfo, options?: NavigationOptions): Promise\<void\> 213e41f4b71Sopenharmony_ci 214e41f4b71Sopenharmony_ci先判断分包是否存在,若不存在,则通过moduleName下载分包,再将info指定的[NavDestination](ts-basic-components-navdestination.md)页面信息入栈,使用Promise异步回调返回接口调用结果,具体根据options中指定不同的[LaunchMode](ts-basic-components-navigation.md#launchmode12枚举说明),有不同的行为。 215e41f4b71Sopenharmony_ci 216e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 217e41f4b71Sopenharmony_ci 218e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 219e41f4b71Sopenharmony_ci 220e41f4b71Sopenharmony_ci**参数:** 221e41f4b71Sopenharmony_ci 222e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 描述 | 223e41f4b71Sopenharmony_ci| ---- | ----------------------------- | ---- | -------------------- | 224e41f4b71Sopenharmony_ci| moduleName | string | 是 | 目标[NavDestination](ts-basic-components-navdestination.md)所在分包的moduleName。 | 225e41f4b71Sopenharmony_ci| info | [NavPathInfo](ts-basic-components-navigation.md#navpathinfo10) | 是 | [NavDestination](ts-basic-components-navdestination.md)页面的信息。 | 226e41f4b71Sopenharmony_ci| options | [NavigationOptions](ts-basic-components-navigation.md#navigationoptions12) | 否 | 页面栈操作选项。 | 227e41f4b71Sopenharmony_ci 228e41f4b71Sopenharmony_ci**返回值:** 229e41f4b71Sopenharmony_ci 230e41f4b71Sopenharmony_ci| 类型 | 说明 | 231e41f4b71Sopenharmony_ci| ------------------- | --------- | 232e41f4b71Sopenharmony_ci| Promise\<void\> | 异常返回结果。 | 233e41f4b71Sopenharmony_ci 234e41f4b71Sopenharmony_ci**错误码:** 235e41f4b71Sopenharmony_ci 236e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../../errorcode-universal.md)和[ohos.router(页面路由)](../errorcode-router.md)错误码。 237e41f4b71Sopenharmony_ci 238e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 239e41f4b71Sopenharmony_ci| --------- | ------- | 240e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed. | 241e41f4b71Sopenharmony_ci| 100001 | Internal error.| 242e41f4b71Sopenharmony_ci| 100005 | Builder function not registered. | 243e41f4b71Sopenharmony_ci| 100006 | NavDestination not found.| 244e41f4b71Sopenharmony_ci| 300001 | hsp silent install fail.| 245e41f4b71Sopenharmony_ci 246e41f4b71Sopenharmony_ci### pushDestinationByName 247e41f4b71Sopenharmony_ci 248e41f4b71Sopenharmony_cipushDestinationByName(moduleName: string, name: string, param: Object, animated?: boolean): Promise\<void\> 249e41f4b71Sopenharmony_ci 250e41f4b71Sopenharmony_ci先判断分包是否存在,若不存在,则通过moduleName下载分包,再将name指定的[NavDestination](ts-basic-components-navdestination.md)页面信息入栈,传递的数据为param,使用Promise异步回调返回接口调用结果。 251e41f4b71Sopenharmony_ci 252e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 253e41f4b71Sopenharmony_ci 254e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 255e41f4b71Sopenharmony_ci 256e41f4b71Sopenharmony_ci**参数:** 257e41f4b71Sopenharmony_ci 258e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 描述 | 259e41f4b71Sopenharmony_ci| ----- | ------- | ---- | --------------------- | 260e41f4b71Sopenharmony_ci| moduleName | string | 是 | 目标[NavDestination](ts-basic-components-navdestination.md)所在分包的moduleName。 | 261e41f4b71Sopenharmony_ci| name | string | 是 | [NavDestination](ts-basic-components-navdestination.md)页面名称。 | 262e41f4b71Sopenharmony_ci| param | Object | 是 | [NavDestination](ts-basic-components-navdestination.md)页面详细参数。 | 263e41f4b71Sopenharmony_ci| animated | boolean | 否 | 是否支持转场动画,默认值:true。 | 264e41f4b71Sopenharmony_ci 265e41f4b71Sopenharmony_ci**返回值:** 266e41f4b71Sopenharmony_ci 267e41f4b71Sopenharmony_ci| 类型 | 说明 | 268e41f4b71Sopenharmony_ci| ------------------- | --------- | 269e41f4b71Sopenharmony_ci| Promise\<void\> | 异常返回结果。 | 270e41f4b71Sopenharmony_ci 271e41f4b71Sopenharmony_ci**错误码:** 272e41f4b71Sopenharmony_ci 273e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../../errorcode-universal.md)和[ohos.router(页面路由)](../errorcode-router.md)错误码。 274e41f4b71Sopenharmony_ci 275e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 276e41f4b71Sopenharmony_ci| --------- | ------- | 277e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed. | 278e41f4b71Sopenharmony_ci| 100001 | Internal error.| 279e41f4b71Sopenharmony_ci| 100005 | Builder function not registered. | 280e41f4b71Sopenharmony_ci| 100006 | NavDestination not found.| 281e41f4b71Sopenharmony_ci| 300001 | hsp silent install fail.| 282e41f4b71Sopenharmony_ci 283e41f4b71Sopenharmony_ci### pushDestinationByName 284e41f4b71Sopenharmony_ci 285e41f4b71Sopenharmony_cipushDestinationByName(moduleName: string, name: string, param: Object, onPop: Callback\<PopInfo>, animated?: boolean): Promise\<void\> 286e41f4b71Sopenharmony_ci 287e41f4b71Sopenharmony_ci先判断分包是否存在,若不存在,则通过moduleName下载分包,再将name指定的[NavDestination](ts-basic-components-navdestination.md)页面信息入栈,传递的数据为param,并且添加用于页面出栈时处理返回结果的OnPop回调,使用Promise异步回调返回接口调用结果。 288e41f4b71Sopenharmony_ci 289e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 290e41f4b71Sopenharmony_ci 291e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 292e41f4b71Sopenharmony_ci 293e41f4b71Sopenharmony_ci**参数:** 294e41f4b71Sopenharmony_ci 295e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 描述 | 296e41f4b71Sopenharmony_ci| ----- | ------- | ---- | --------------------- | 297e41f4b71Sopenharmony_ci| moduleName | string | 是 | 目标[NavDestination](ts-basic-components-navdestination.md)所在分包的moduleName。 | 298e41f4b71Sopenharmony_ci| name | string | 是 | [NavDestination](ts-basic-components-navdestination.md)页面名称。 | 299e41f4b71Sopenharmony_ci| param | Object | 是 | [NavDestination](ts-basic-components-navdestination.md)页面详细参数。 | 300e41f4b71Sopenharmony_ci| onPop | Callback\<[PopInfo](ts-basic-components-navigation.md#popinfo11)> | 是 | Callback回调,用于页面出栈时处理返回结果。 | 301e41f4b71Sopenharmony_ci| animated | boolean | 否 | 是否支持转场动画,默认值:true。 | 302e41f4b71Sopenharmony_ci 303e41f4b71Sopenharmony_ci**返回值:** 304e41f4b71Sopenharmony_ci 305e41f4b71Sopenharmony_ci| 类型 | 说明 | 306e41f4b71Sopenharmony_ci| ------------------- | --------- | 307e41f4b71Sopenharmony_ci| Promise\<void\> | 异常返回结果。 | 308e41f4b71Sopenharmony_ci 309e41f4b71Sopenharmony_ci**错误码:** 310e41f4b71Sopenharmony_ci 311e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../../errorcode-universal.md)和[ohos.router(页面路由)](../errorcode-router.md)错误码。 312e41f4b71Sopenharmony_ci 313e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 314e41f4b71Sopenharmony_ci| --------- | ------- | 315e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2.Incorrect parameter types; 3. Parameter verification failed. | 316e41f4b71Sopenharmony_ci| 100001 | Internal error.| 317e41f4b71Sopenharmony_ci| 100005 | Builder function not registered. | 318e41f4b71Sopenharmony_ci| 100006 | NavDestination not found.| 319e41f4b71Sopenharmony_ci| 300001 | hsp silent install fail.| 320e41f4b71Sopenharmony_ci 321e41f4b71Sopenharmony_ci### replacePath 322e41f4b71Sopenharmony_ci 323e41f4b71Sopenharmony_cireplacePath(moduleName: string, info: NavPathInfo, animated?: boolean): Promise\<void\> 324e41f4b71Sopenharmony_ci 325e41f4b71Sopenharmony_ci先判断分包是否存在,若不存在,则通过moduleName下载分包,再将当前页面栈栈顶退出,将info指定的[NavDestination](ts-basic-components-navdestination.md)页面信息入栈,使用Promise异步回调返回接口调用结果。 326e41f4b71Sopenharmony_ci 327e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 328e41f4b71Sopenharmony_ci 329e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 330e41f4b71Sopenharmony_ci 331e41f4b71Sopenharmony_ci**参数:** 332e41f4b71Sopenharmony_ci 333e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 描述 | 334e41f4b71Sopenharmony_ci| ---- | ----------------------------- | ---- | -------------------- | 335e41f4b71Sopenharmony_ci| moduleName | string | 是 | 目标[NavDestination](ts-basic-components-navdestination.md)所在分包的moduleName。 | 336e41f4b71Sopenharmony_ci| info | [NavPathInfo](ts-basic-components-navigation.md#navpathinfo10) | 是 | 新栈顶页面参数信息 | 337e41f4b71Sopenharmony_ci| animated | boolean | 否 | 是否支持转场动画,默认值:true。 | 338e41f4b71Sopenharmony_ci 339e41f4b71Sopenharmony_ci**返回值:** 340e41f4b71Sopenharmony_ci 341e41f4b71Sopenharmony_ci| 类型 | 说明 | 342e41f4b71Sopenharmony_ci| ------------------- | --------- | 343e41f4b71Sopenharmony_ci| Promise\<void\> | 异常返回结果。 | 344e41f4b71Sopenharmony_ci 345e41f4b71Sopenharmony_ci**错误码:** 346e41f4b71Sopenharmony_ci 347e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[ohos.router(页面路由)](../errorcode-router.md)错误码。 348e41f4b71Sopenharmony_ci 349e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 350e41f4b71Sopenharmony_ci| --------- | ------- | 351e41f4b71Sopenharmony_ci| 300001 | hsp silent install fail.| 352e41f4b71Sopenharmony_ci 353e41f4b71Sopenharmony_ci### replacePath 354e41f4b71Sopenharmony_ci 355e41f4b71Sopenharmony_cireplacePath(moduleName: string, info: NavPathInfo, options?: NavigationOptions): Promise\<void\> 356e41f4b71Sopenharmony_ci 357e41f4b71Sopenharmony_ci先判断分包是否存在,若不存在,则通过moduleName下载分包,再将当前页面栈栈顶退出,使用Promise异步回调返回接口调用结果,具体根据options中指定不同的[LaunchMode](ts-basic-components-navigation.md#launchmode12枚举说明),有不同的行为。 358e41f4b71Sopenharmony_ci 359e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 360e41f4b71Sopenharmony_ci 361e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 362e41f4b71Sopenharmony_ci 363e41f4b71Sopenharmony_ci**参数:** 364e41f4b71Sopenharmony_ci 365e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 描述 | 366e41f4b71Sopenharmony_ci| ---- | ----------------------------- | ---- | -------------------- | 367e41f4b71Sopenharmony_ci| moduleName | string | 是 | 目标[NavDestination](ts-basic-components-navdestination.md)所在分包的moduleName。 | 368e41f4b71Sopenharmony_ci| info | [NavPathInfo](ts-basic-components-navigation.md#navpathinfo10) | 是 | 新栈顶页面参数信息。 | 369e41f4b71Sopenharmony_ci| options | [NavigationOptions](ts-basic-components-navigation.md#navigationoptions12) | 否 | 页面栈操作选项。 | 370e41f4b71Sopenharmony_ci 371e41f4b71Sopenharmony_ci**返回值:** 372e41f4b71Sopenharmony_ci 373e41f4b71Sopenharmony_ci| 类型 | 说明 | 374e41f4b71Sopenharmony_ci| ------------------- | --------- | 375e41f4b71Sopenharmony_ci| Promise\<void\> | 异常返回结果。 | 376e41f4b71Sopenharmony_ci 377e41f4b71Sopenharmony_ci**错误码:** 378e41f4b71Sopenharmony_ci 379e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[ohos.router(页面路由)](../errorcode-router.md)错误码。 380e41f4b71Sopenharmony_ci 381e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 382e41f4b71Sopenharmony_ci| --------- | ------- | 383e41f4b71Sopenharmony_ci| 300001 | hsp silent install fail.| 384e41f4b71Sopenharmony_ci 385e41f4b71Sopenharmony_ci### replacePathByName 386e41f4b71Sopenharmony_ci 387e41f4b71Sopenharmony_cireplacePathByName(moduleName: string, name: string, param: Object, animated?: boolean): Promise\<void\> 388e41f4b71Sopenharmony_ci 389e41f4b71Sopenharmony_ci先判断分包是否存在,若不存在,则通过moduleName下载分包,再将当前页面栈栈顶退出,将name指定的页面入栈,使用Promise异步回调返回接口调用结果。 390e41f4b71Sopenharmony_ci 391e41f4b71Sopenharmony_ci**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 392e41f4b71Sopenharmony_ci 393e41f4b71Sopenharmony_ci**系统能力:** SystemCapability.ArkUI.ArkUI.Full 394e41f4b71Sopenharmony_ci 395e41f4b71Sopenharmony_ci**参数:** 396e41f4b71Sopenharmony_ci 397e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 描述 | 398e41f4b71Sopenharmony_ci| ----- | ------- | ---- | --------------------- | 399e41f4b71Sopenharmony_ci| moduleName | string | 是 | 目标[NavDestination](ts-basic-components-navdestination.md)所在分包的moduleName。 | 400e41f4b71Sopenharmony_ci| name | string | 是 | [NavDestination](ts-basic-components-navdestination.md)页面名称。 | 401e41f4b71Sopenharmony_ci| param | Object | 是 | [NavDestination](ts-basic-components-navdestination.md)页面详细参数。 | 402e41f4b71Sopenharmony_ci| animated | boolean | 否 | 是否支持转场动画,默认值:true。 | 403e41f4b71Sopenharmony_ci 404e41f4b71Sopenharmony_ci**返回值:** 405e41f4b71Sopenharmony_ci 406e41f4b71Sopenharmony_ci| 类型 | 说明 | 407e41f4b71Sopenharmony_ci| ------------------- | --------- | 408e41f4b71Sopenharmony_ci| Promise\<void\> | 异常返回结果。 | 409e41f4b71Sopenharmony_ci 410e41f4b71Sopenharmony_ci**错误码:** 411e41f4b71Sopenharmony_ci 412e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[ohos.router(页面路由)](../errorcode-router.md)错误码。 413e41f4b71Sopenharmony_ci 414e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 415e41f4b71Sopenharmony_ci| --------- | ------- | 416e41f4b71Sopenharmony_ci| 300001 | hsp silent install fail.| 417e41f4b71Sopenharmony_ci 418e41f4b71Sopenharmony_ci## 事件 419e41f4b71Sopenharmony_ci 420e41f4b71Sopenharmony_ci不支持[通用事件](ts-universal-events-click.md) 421e41f4b71Sopenharmony_ci 422e41f4b71Sopenharmony_ci## 示例 423e41f4b71Sopenharmony_ci 424e41f4b71Sopenharmony_ci主包: 425e41f4b71Sopenharmony_ci```ts 426e41f4b71Sopenharmony_ci// Index.ets 427e41f4b71Sopenharmony_ciimport { NavPushPathHelper } from '@kit.ArkUI' 428e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 429e41f4b71Sopenharmony_ci@Entry 430e41f4b71Sopenharmony_ci@Component 431e41f4b71Sopenharmony_cistruct NavigationExample { 432e41f4b71Sopenharmony_ci pageInfo: NavPathStack = new NavPathStack() 433e41f4b71Sopenharmony_ci helper: NavPushPathHelper = new NavPushPathHelper(this.pageInfo) 434e41f4b71Sopenharmony_ci 435e41f4b71Sopenharmony_ci build() { 436e41f4b71Sopenharmony_ci Navigation(this.pageInfo) { 437e41f4b71Sopenharmony_ci Column() { 438e41f4b71Sopenharmony_ci Button('StartTest', { stateEffect: true, type: ButtonType.Capsule }) 439e41f4b71Sopenharmony_ci .width('80%') 440e41f4b71Sopenharmony_ci .height(40) 441e41f4b71Sopenharmony_ci .margin(20) 442e41f4b71Sopenharmony_ci .onClick(() => { 443e41f4b71Sopenharmony_ci this.helper.pushPath('hsptest1', { name: 'pageOne' }, false) 444e41f4b71Sopenharmony_ci .catch((error: BusinessError) => { 445e41f4b71Sopenharmony_ci console.error(`[pushPath]failed, error code = ${error.code}, error.message = ${error.message}.`); 446e41f4b71Sopenharmony_ci }).then(() => { 447e41f4b71Sopenharmony_ci console.error('[pushPath]success.'); 448e41f4b71Sopenharmony_ci }); // 将name指定的NavDestination页面信息入栈。 449e41f4b71Sopenharmony_ci }) 450e41f4b71Sopenharmony_ci } 451e41f4b71Sopenharmony_ci }.title('NavIndex') 452e41f4b71Sopenharmony_ci } 453e41f4b71Sopenharmony_ci} 454e41f4b71Sopenharmony_ci``` 455e41f4b71Sopenharmony_ci分包hsptest1: 456e41f4b71Sopenharmony_ci```ts 457e41f4b71Sopenharmony_ci// PageOne.ets 458e41f4b71Sopenharmony_ciimport { NavPushPathHelper } from '@kit.ArkUI' 459e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 460e41f4b71Sopenharmony_ci 461e41f4b71Sopenharmony_ciclass TmpClass { 462e41f4b71Sopenharmony_ci count: number = 10 463e41f4b71Sopenharmony_ci} 464e41f4b71Sopenharmony_ci 465e41f4b71Sopenharmony_ciclass ParamWithOp { 466e41f4b71Sopenharmony_ci operation: number = 1 467e41f4b71Sopenharmony_ci count: number = 10 468e41f4b71Sopenharmony_ci} 469e41f4b71Sopenharmony_ci 470e41f4b71Sopenharmony_ci@Builder 471e41f4b71Sopenharmony_ciexport function PageOneBuilder(name: string, param: Object) { 472e41f4b71Sopenharmony_ci PageOne() 473e41f4b71Sopenharmony_ci} 474e41f4b71Sopenharmony_ci 475e41f4b71Sopenharmony_ci@Component 476e41f4b71Sopenharmony_ciexport struct PageOne { 477e41f4b71Sopenharmony_ci pageInfo: NavPathStack = new NavPathStack(); 478e41f4b71Sopenharmony_ci helper: NavPushPathHelper = new NavPushPathHelper(this.pageInfo) 479e41f4b71Sopenharmony_ci @State message: string = 'Hello World' 480e41f4b71Sopenharmony_ci 481e41f4b71Sopenharmony_ci build() { 482e41f4b71Sopenharmony_ci NavDestination() { 483e41f4b71Sopenharmony_ci Column() { 484e41f4b71Sopenharmony_ci Text(this.message) 485e41f4b71Sopenharmony_ci .width('80%') 486e41f4b71Sopenharmony_ci .height(50) 487e41f4b71Sopenharmony_ci .margin(10) 488e41f4b71Sopenharmony_ci 489e41f4b71Sopenharmony_ci Button('pushPath', { stateEffect: true, type: ButtonType.Capsule }) 490e41f4b71Sopenharmony_ci .width('80%') 491e41f4b71Sopenharmony_ci .height(35) 492e41f4b71Sopenharmony_ci .margin(10) 493e41f4b71Sopenharmony_ci .onClick(() => { 494e41f4b71Sopenharmony_ci this.helper.pushPath('hsptest2', { name: 'pageTwo', param: new ParamWithOp(), onPop: (popInfo: PopInfo) => { 495e41f4b71Sopenharmony_ci this.message = '[pushPath]last page is: ' + popInfo.info.name + ', result: ' + JSON.stringify(popInfo.result); 496e41f4b71Sopenharmony_ci }}).catch((error: BusinessError) => { 497e41f4b71Sopenharmony_ci console.error(`[pushPath]failed, error code = ${error.code}, error.message = ${error.message}.`); 498e41f4b71Sopenharmony_ci }).then(() => { 499e41f4b71Sopenharmony_ci console.log('[pushPath]success.'); 500e41f4b71Sopenharmony_ci }); 501e41f4b71Sopenharmony_ci }) 502e41f4b71Sopenharmony_ci 503e41f4b71Sopenharmony_ci Button('pushPath with NavigationOptions', { stateEffect: true, type: ButtonType.Capsule }) 504e41f4b71Sopenharmony_ci .width('80%') 505e41f4b71Sopenharmony_ci .height(35) 506e41f4b71Sopenharmony_ci .margin(10) 507e41f4b71Sopenharmony_ci .onClick(() => { 508e41f4b71Sopenharmony_ci this.helper.pushPath('hsptest2', { name: 'pageTwo', param: new ParamWithOp(), onPop: (popInfo: PopInfo) => { 509e41f4b71Sopenharmony_ci this.message = '[pushPath with NavigationOptions]last page is: ' + popInfo.info.name + ', result: ' + JSON.stringify(popInfo.result); 510e41f4b71Sopenharmony_ci }}, {launchMode:0, animated:true}).catch((error: BusinessError) => { 511e41f4b71Sopenharmony_ci console.error(`[pushPath with NavigationOptions]failed, error code = ${error.code}, error.message = ${error.message}.`); 512e41f4b71Sopenharmony_ci }).then(() => { 513e41f4b71Sopenharmony_ci console.log('[pushPath with NavigationOptions]success.'); 514e41f4b71Sopenharmony_ci }); 515e41f4b71Sopenharmony_ci }) 516e41f4b71Sopenharmony_ci 517e41f4b71Sopenharmony_ci Button('pushPathByName', { stateEffect: true, type: ButtonType.Capsule }) 518e41f4b71Sopenharmony_ci .width('80%') 519e41f4b71Sopenharmony_ci .height(35) 520e41f4b71Sopenharmony_ci .margin(10) 521e41f4b71Sopenharmony_ci .onClick(() => { 522e41f4b71Sopenharmony_ci let tmp = new TmpClass() 523e41f4b71Sopenharmony_ci this.helper.pushPathByName('hsptest2', 'pageTwo', tmp, (popInfo) => { 524e41f4b71Sopenharmony_ci this.message = '[pushPathByName]last page is: ' + popInfo.info.name + ', result: ' + JSON.stringify(popInfo.result); 525e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 526e41f4b71Sopenharmony_ci console.error(`[pushPathByName]failed, error code = ${error.code}, error.message = ${error.message}.`); 527e41f4b71Sopenharmony_ci }).then(() => { 528e41f4b71Sopenharmony_ci console.log('[pushPathByName]success.'); 529e41f4b71Sopenharmony_ci }); 530e41f4b71Sopenharmony_ci }) 531e41f4b71Sopenharmony_ci 532e41f4b71Sopenharmony_ci Button('pushPathByNameWithoutOnPop', { stateEffect: true, type: ButtonType.Capsule }) 533e41f4b71Sopenharmony_ci .width('80%') 534e41f4b71Sopenharmony_ci .height(35) 535e41f4b71Sopenharmony_ci .margin(10) 536e41f4b71Sopenharmony_ci .onClick(() => { 537e41f4b71Sopenharmony_ci let tmp = new TmpClass() 538e41f4b71Sopenharmony_ci this.helper.pushPathByName('hsptest2', 'pageTwo', tmp, true) 539e41f4b71Sopenharmony_ci .catch((error: BusinessError) => { 540e41f4b71Sopenharmony_ci console.error(`[pushPathByNameWithoutOnPop]failed, error code = ${error.code}, error.message = ${error.message}.`); 541e41f4b71Sopenharmony_ci }).then(() => { 542e41f4b71Sopenharmony_ci console.log('[pushPathByNameWithoutOnPop]success.'); 543e41f4b71Sopenharmony_ci }); 544e41f4b71Sopenharmony_ci }) 545e41f4b71Sopenharmony_ci 546e41f4b71Sopenharmony_ci Button('pushDestination', { stateEffect: true, type: ButtonType.Capsule }) 547e41f4b71Sopenharmony_ci .width('80%') 548e41f4b71Sopenharmony_ci .height(35) 549e41f4b71Sopenharmony_ci .margin(10) 550e41f4b71Sopenharmony_ci .onClick(() => { 551e41f4b71Sopenharmony_ci let tmp = new TmpClass() 552e41f4b71Sopenharmony_ci this.helper.pushDestination('hsptest2', { name: 'pageTwo', param: new ParamWithOp(), onPop: (popInfo: PopInfo) => { 553e41f4b71Sopenharmony_ci this.message = '[pushDestination]last page is: ' + popInfo.info.name + ', result: ' + JSON.stringify(popInfo.result); 554e41f4b71Sopenharmony_ci }}).catch((error: BusinessError) => { 555e41f4b71Sopenharmony_ci console.error(`[pushDestination]failed, error code = ${error.code}, error.message = ${error.message}.`); 556e41f4b71Sopenharmony_ci }).then(() => { 557e41f4b71Sopenharmony_ci console.error('[pushDestination]success.'); 558e41f4b71Sopenharmony_ci }); 559e41f4b71Sopenharmony_ci }) 560e41f4b71Sopenharmony_ci 561e41f4b71Sopenharmony_ci Button('pushDestination with NavigationOptions', { stateEffect: true, type: ButtonType.Capsule }) 562e41f4b71Sopenharmony_ci .width('80%') 563e41f4b71Sopenharmony_ci .height(35) 564e41f4b71Sopenharmony_ci .margin(10) 565e41f4b71Sopenharmony_ci .onClick(() => { 566e41f4b71Sopenharmony_ci let tmp = new TmpClass() 567e41f4b71Sopenharmony_ci this.helper.pushDestination('hsptest2', { name: 'pageTwo', param: new ParamWithOp(), onPop: (popInfo: PopInfo) => { 568e41f4b71Sopenharmony_ci this.message = '[pushDestination with NavigationOptions]last page is: ' + popInfo.info.name + ', result: ' + JSON.stringify(popInfo.result); 569e41f4b71Sopenharmony_ci }}, {launchMode:0, animated:true}).catch((error: BusinessError) => { 570e41f4b71Sopenharmony_ci console.error(`[pushDestination with NavigationOptions]failed, error code = ${error.code}, error.message = ${error.message}.`); 571e41f4b71Sopenharmony_ci }).then(() => { 572e41f4b71Sopenharmony_ci console.error('[pushDestination with NavigationOptions]success.'); 573e41f4b71Sopenharmony_ci }); 574e41f4b71Sopenharmony_ci }) 575e41f4b71Sopenharmony_ci 576e41f4b71Sopenharmony_ci Button('pushDestinationByName', { stateEffect: true, type: ButtonType.Capsule }) 577e41f4b71Sopenharmony_ci .width('80%') 578e41f4b71Sopenharmony_ci .height(35) 579e41f4b71Sopenharmony_ci .margin(10) 580e41f4b71Sopenharmony_ci .onClick(() => { 581e41f4b71Sopenharmony_ci let tmp = new TmpClass() 582e41f4b71Sopenharmony_ci this.helper.pushDestinationByName('hsptest2','pageTwo', tmp, (popInfo) => { 583e41f4b71Sopenharmony_ci this.message = '[pushDestinationByName]last page is: ' + popInfo.info.name + ', result: ' + JSON.stringify(popInfo.result); 584e41f4b71Sopenharmony_ci }).catch((error: BusinessError) => { 585e41f4b71Sopenharmony_ci console.error(`[pushDestinationByName]failed, error code = ${error.code}, error.message = ${error.message}.`); 586e41f4b71Sopenharmony_ci }).then(() => { 587e41f4b71Sopenharmony_ci console.error('[pushDestinationByName]success.'); 588e41f4b71Sopenharmony_ci }); 589e41f4b71Sopenharmony_ci }) 590e41f4b71Sopenharmony_ci 591e41f4b71Sopenharmony_ci Button('pushDestinationByNameWithoutOnPop', { stateEffect: true, type: ButtonType.Capsule }) 592e41f4b71Sopenharmony_ci .width('80%') 593e41f4b71Sopenharmony_ci .height(35) 594e41f4b71Sopenharmony_ci .margin(10) 595e41f4b71Sopenharmony_ci .onClick(() => { 596e41f4b71Sopenharmony_ci let tmp = new TmpClass() 597e41f4b71Sopenharmony_ci this.helper.pushDestinationByName('hsptest2','pageTwo', tmp, true) 598e41f4b71Sopenharmony_ci .catch((error: BusinessError) => { 599e41f4b71Sopenharmony_ci console.error(`[pushDestinationByNameWithoutOnPop]failed, error code = ${error.code}, error.message = ${error.message}.`); 600e41f4b71Sopenharmony_ci }).then(() => { 601e41f4b71Sopenharmony_ci console.error('[pushDestinationByNameWithoutOnPop]success.'); 602e41f4b71Sopenharmony_ci }); 603e41f4b71Sopenharmony_ci }) 604e41f4b71Sopenharmony_ci 605e41f4b71Sopenharmony_ci Button('replacePath', { stateEffect: true, type: ButtonType.Capsule }) 606e41f4b71Sopenharmony_ci .width('80%') 607e41f4b71Sopenharmony_ci .height(35) 608e41f4b71Sopenharmony_ci .margin(10) 609e41f4b71Sopenharmony_ci .onClick(() => { 610e41f4b71Sopenharmony_ci this.helper.replacePath('hsptest2', { name: 'pageTwo', param: new ParamWithOp(), onPop: (popInfo: PopInfo) => { 611e41f4b71Sopenharmony_ci this.message = '[replacePath]last page is: ' + popInfo.info.name + ', result: ' + JSON.stringify(popInfo.result); 612e41f4b71Sopenharmony_ci }}).catch((error: BusinessError) => { 613e41f4b71Sopenharmony_ci console.error(`[replacePath]failed, error code = ${error.code}, error.message = ${error.message}.`); 614e41f4b71Sopenharmony_ci }).then(() => { 615e41f4b71Sopenharmony_ci console.log('[replacePath]success.'); 616e41f4b71Sopenharmony_ci }); 617e41f4b71Sopenharmony_ci }) 618e41f4b71Sopenharmony_ci 619e41f4b71Sopenharmony_ci Button('replacePath with NavigationOptions', { stateEffect: true, type: ButtonType.Capsule }) 620e41f4b71Sopenharmony_ci .width('80%') 621e41f4b71Sopenharmony_ci .height(35) 622e41f4b71Sopenharmony_ci .margin(10) 623e41f4b71Sopenharmony_ci .onClick(() => { 624e41f4b71Sopenharmony_ci this.helper.replacePath('hsptest2', { name: 'pageTwo', param: new ParamWithOp(), onPop: (popInfo: PopInfo) => { 625e41f4b71Sopenharmony_ci this.message = '[replacePath with NavigationOptions]last page is: ' + popInfo.info.name + ', result: ' + JSON.stringify(popInfo.result); 626e41f4b71Sopenharmony_ci }}, {launchMode:0, animated:true}).catch((error: BusinessError) => { 627e41f4b71Sopenharmony_ci console.error(`[replacePath with NavigationOptions]failed, error code = ${error.code}, error.message = ${error.message}.`); 628e41f4b71Sopenharmony_ci }).then(() => { 629e41f4b71Sopenharmony_ci console.log('[replacePath with NavigationOptions]success.'); 630e41f4b71Sopenharmony_ci }); 631e41f4b71Sopenharmony_ci }) 632e41f4b71Sopenharmony_ci 633e41f4b71Sopenharmony_ci Button('replacePathByName', { stateEffect: true, type: ButtonType.Capsule }) 634e41f4b71Sopenharmony_ci .width('80%') 635e41f4b71Sopenharmony_ci .height(35) 636e41f4b71Sopenharmony_ci .margin(10) 637e41f4b71Sopenharmony_ci .onClick(() => { 638e41f4b71Sopenharmony_ci let tmp = new TmpClass() 639e41f4b71Sopenharmony_ci this.helper.replacePathByName('hsptest2', 'pageTwo', tmp) 640e41f4b71Sopenharmony_ci .catch((error: BusinessError) => { 641e41f4b71Sopenharmony_ci console.error(`[replacePathByName]failed, error code = ${error.code}, error.message = ${error.message}.`); 642e41f4b71Sopenharmony_ci }).then(() => { 643e41f4b71Sopenharmony_ci console.log('[replacePathByName]success.'); 644e41f4b71Sopenharmony_ci }); 645e41f4b71Sopenharmony_ci }) 646e41f4b71Sopenharmony_ci 647e41f4b71Sopenharmony_ci }.width('100%').height('100%') 648e41f4b71Sopenharmony_ci }.title('pageOne') 649e41f4b71Sopenharmony_ci .onBackPressed(() => { 650e41f4b71Sopenharmony_ci this.pageInfo.pop({ number: 1 }) // 弹出路由栈栈顶元素。 651e41f4b71Sopenharmony_ci return true 652e41f4b71Sopenharmony_ci }).onReady((context: NavDestinationContext) => { 653e41f4b71Sopenharmony_ci this.pageInfo = context.pathStack; 654e41f4b71Sopenharmony_ci this.helper = new NavPushPathHelper(this.pageInfo); 655e41f4b71Sopenharmony_ci }) 656e41f4b71Sopenharmony_ci } 657e41f4b71Sopenharmony_ci} 658e41f4b71Sopenharmony_ci``` 659e41f4b71Sopenharmony_ci 660e41f4b71Sopenharmony_ci```json 661e41f4b71Sopenharmony_ci// 工程配置文件module.json5中配置 {"routerMap": "$profile:route_map"} 662e41f4b71Sopenharmony_ci// route_map.json 663e41f4b71Sopenharmony_ci{ 664e41f4b71Sopenharmony_ci "routerMap": [ 665e41f4b71Sopenharmony_ci { 666e41f4b71Sopenharmony_ci "name": "pageOne", 667e41f4b71Sopenharmony_ci "pageSourceFile": "src/main/ets/pages/PageOne.ets", 668e41f4b71Sopenharmony_ci "buildFunction": "PageOneBuilder", 669e41f4b71Sopenharmony_ci "data": { 670e41f4b71Sopenharmony_ci "description": "this is pageOne" 671e41f4b71Sopenharmony_ci } 672e41f4b71Sopenharmony_ci } 673e41f4b71Sopenharmony_ci ] 674e41f4b71Sopenharmony_ci} 675e41f4b71Sopenharmony_ci``` 676e41f4b71Sopenharmony_ci 677e41f4b71Sopenharmony_ci分包hsptest2: 678e41f4b71Sopenharmony_ci```ts 679e41f4b71Sopenharmony_ci// PageTwo.ets 680e41f4b71Sopenharmony_ci 681e41f4b71Sopenharmony_ciclass resultClass { 682e41f4b71Sopenharmony_ci constructor(count: number) { 683e41f4b71Sopenharmony_ci this.count = count; 684e41f4b71Sopenharmony_ci } 685e41f4b71Sopenharmony_ci count: number = 10 686e41f4b71Sopenharmony_ci} 687e41f4b71Sopenharmony_ci 688e41f4b71Sopenharmony_ci@Builder 689e41f4b71Sopenharmony_ciexport function PageTwoBuilder() { 690e41f4b71Sopenharmony_ci PageTwo() 691e41f4b71Sopenharmony_ci} 692e41f4b71Sopenharmony_ci 693e41f4b71Sopenharmony_ci@Component 694e41f4b71Sopenharmony_ciexport struct PageTwo { 695e41f4b71Sopenharmony_ci pathStack: NavPathStack = new NavPathStack() 696e41f4b71Sopenharmony_ci 697e41f4b71Sopenharmony_ci build() { 698e41f4b71Sopenharmony_ci NavDestination() { 699e41f4b71Sopenharmony_ci Column() { 700e41f4b71Sopenharmony_ci Button('pop', { stateEffect: true, type: ButtonType.Capsule }) 701e41f4b71Sopenharmony_ci .width('80%') 702e41f4b71Sopenharmony_ci .height(40) 703e41f4b71Sopenharmony_ci .margin(20) 704e41f4b71Sopenharmony_ci .onClick(() => { 705e41f4b71Sopenharmony_ci this.pathStack.pop(new resultClass(1)); // 回退到上一个页面,将处理结果传入push的onPop回调中。 706e41f4b71Sopenharmony_ci }) 707e41f4b71Sopenharmony_ci }.width('100%').height('100%') 708e41f4b71Sopenharmony_ci }.title('pageTwo') 709e41f4b71Sopenharmony_ci .onBackPressed(() => { 710e41f4b71Sopenharmony_ci this.pathStack.pop(new resultClass(0)); // 回退到上一个页面,将处理结果传入push的onPop回调。 711e41f4b71Sopenharmony_ci return true; 712e41f4b71Sopenharmony_ci }).onReady((context: NavDestinationContext) => { 713e41f4b71Sopenharmony_ci this.pathStack = context.pathStack 714e41f4b71Sopenharmony_ci }) 715e41f4b71Sopenharmony_ci } 716e41f4b71Sopenharmony_ci} 717e41f4b71Sopenharmony_ci``` 718e41f4b71Sopenharmony_ci 719e41f4b71Sopenharmony_ci```json 720e41f4b71Sopenharmony_ci// 工程配置文件module.json5中配置 {"routerMap": "$profile:route_map"} 721e41f4b71Sopenharmony_ci// route_map.json 722e41f4b71Sopenharmony_ci{ 723e41f4b71Sopenharmony_ci "routerMap": [ 724e41f4b71Sopenharmony_ci { 725e41f4b71Sopenharmony_ci "name": "pageTwo", 726e41f4b71Sopenharmony_ci "pageSourceFile": "src/main/ets/pages/PageTwo.ets", 727e41f4b71Sopenharmony_ci "buildFunction": "PageTwoBuilder", 728e41f4b71Sopenharmony_ci "data": { 729e41f4b71Sopenharmony_ci "description": "this is pageTwo" 730e41f4b71Sopenharmony_ci } 731e41f4b71Sopenharmony_ci } 732e41f4b71Sopenharmony_ci ] 733e41f4b71Sopenharmony_ci} 734e41f4b71Sopenharmony_ci``` 735e41f4b71Sopenharmony_ci 736