---
name: "navigateToMiniProgram"
mode: "kit"
versionRequirements:
  - { name: "BaseKit", version: "2.2.4" }
  - { name: "@ray-js/ray", version: "0.3.23" }
platform:
  - "iOS"
  - "Android"
async: true
title: "navigateToMiniProgram - 打开另一个小程序"
---

## navigateToMiniProgram

> [VERSION] BaseKit >= 2.2.4 | @ray-js/ray >= 0.3.23

> [PLATFORM] iOS, Android

> ⚡ **支持 Promise 调用** — 不传 success / fail / complete 回调时，该方法返回 Promise。

### 描述

打开另一个小程序

### 参数

| 属性 | 类型 | 必填 | 默认值 | 最低版本 | 描述 |
| --- | --- | --- | --- | --- | --- |
| `appId` | `string` | 否 | - | `2.2.4` | 要打开的小程序appId |
| `aiPtChannel` | `string` | 否 | - | `3.13.0` | 要打开的智能体小程序的智能体Id |
| `aiPtType` | `string` | 否 | `"release"` | `3.13.0` | 要打开的小程序智能体的版本。 preview：体验版 release：正式版 |
| `path` | `string` | 否 | - | `2.2.4` | 打开的页面路径,如果为空则打开首页,path 中 ? 后面的部分会成为 query，在小程序的 `App.onLaunch`、`App.onShow` 和 `Page.onLoad` 的回调函数 |
| `position` | `string` | 否 | `"right"` | `2.5.1` | 打开小程序的转场方式,分为right\|bottom,指代水平和竖直方向 |
| `extraData` | `Record<string, any>` | 否 | - | `2.2.4` | 传递给目标小程序的数据,目标小程序可在 `App.onLaunch`，`App.onShow` 中获取到这份数据 |
| `envVersion` | `string` | 否 | `"release"` | `2.2.4` | 要打开的小程序版本。仅在当前小程序为开发版或体验版时此参数有效。如果当前小程序是正式版，则打开的小程序必定是正式版 trial：体验版 release：正式版 |
| `shortLink` | `string` | 否 | - | `2.2.4` | 小程序链接，当传递该参数后，可以不传 appId 和 path |
| `complete` | `() => void` | 否 | - | - | 接口调用结束的回调函数（调用成功、失败都会执行） |
| `success` | `() => void` | 否 | - | - | 接口调用成功的回调函数 |
| `fail` | `(params: Object) => void` ↓见下方 | 否 | - | - | 接口调用失败的回调函数 |

#### fail 回调参数

| 属性 | 类型 | 描述 |
| --- | --- | --- |
| `errorMsg` | `string` | 错误信息 |
| `errorCode` | `string \| number` | 错误码 |
| `innerError` | `Object` | 错误扩展 |

##### fail(params).innerError 的属性

| 属性 | 类型 | 描述 |
| --- | --- | --- |
| `errorCode` | `string \| number` | 错误扩展码 |
| `errorMsg` | `string` | 错误扩展信息 |


### 示例代码

#### Demo

```tsx
import { navigateToMiniProgram } from '@ray-js/ray'

navigateToMiniProgram({
  appId: "tyeavwo0j4oocvdrf1",
  path: "pages/myService/index?categoryCode=ai_inspection_service",
  position: "right",
  envVersion: "release",
  extraData: { source: "ttt-demo", debug: true },
  success: data => {
    console.log(data);
  },
  fail: error => {
    console.error(error);
  },
});
```
