小程序API能力集成指南——路由API汇总

ty.navigateBack

关闭当前页面,返回上一页面或多级页面

需引入MiniKit,且在>=2.0.0版本才可使用

参数

Object object

属性 类型 默认值 必填 说明
delta number 返回的页面数,如果 delta 大于现有页面数,则返回到首页
complete function 接口调用结束的回调函数(调用成功、失败都会执行)
success function 接口调用成功的回调函数
fail function 接口调用失败的回调函数

函数定义示例

复制代码
/**
 * 关闭当前页面,返回上一页面或多级页面
 */
export function navigateBack(params?: {
  /** 返回的页面数,如果 delta 大于现有页面数,则返回到首页 */
  delta?: number;
  complete?: () => void;
  success?: (params: null) => void;
  fail?: (params: {
    errorMsg: string;
    errorCode: string | number;
    innerError: {
      errorCode: string | number;
      errorMsg: string;
    };
  }) => void;
}): void;

ty.navigateTo

路由到新页面

需引入MiniKit,且在>=2.0.0版本才可使用

参数

Object object

属性 类型 默认值 必填 说明
url string 页面路径
type string 打开方式,支持全屏 full,半屏 half;默认全屏 full
complete function 接口调用结束的回调函数(调用成功、失败都会执行)
success function 接口调用成功的回调函数
fail function 接口调用失败的回调函数

函数定义示例

复制代码
/**
 * 路由到新页面
 */
export function navigateTo(params: {
  /** 页面路径 */
  url: string;
  /** 打开方式,支持全屏full,半屏half;默认全屏full */
  type?: string;
  complete?: () => void;
  success?: (params: null) => void;
  fail?: (params: {
    errorMsg: string;
    errorCode: string | number;
    innerError: {
      errorCode: string | number;
      errorMsg: string;
    };
  }) => void;
}): void;

ty.redirectTo

关闭当前页面,跳转到应用内的某个页面

需引入MiniKit,且在>=2.0.0版本才可使用

参数

Object object

属性 类型 默认值 必填 说明
url string 页面路径
type string 打开方式,支持全屏 full,半屏 half;默认全屏 full
complete function 接口调用结束的回调函数(调用成功、失败都会执行)
success function 接口调用成功的回调函数
fail function 接口调用失败的回调函数

函数定义示例

复制代码
/**
 * 关闭当前页面,跳转到应用内的某个页面
 */
export function redirectTo(params: {
  /** 页面路径 */
  url: string;
  /** 打开方式,支持全屏full,半屏half;默认全屏full */
  type?: string;
  complete?: () => void;
  success?: (params: null) => void;
  fail?: (params: {
    errorMsg: string;
    errorCode: string | number;
    innerError: {
      errorCode: string | number;
      errorMsg: string;
    };
  }) => void;
}): void;

ty.reLaunch

关闭所有页面,打开到应用内的某个页面

需引入MiniKit,且在>=2.0.0版本才可使用

参数

Object object

属性 类型 默认值 必填 说明
url string 页面路径
type string 打开方式,支持全屏 full,半屏 half;默认全屏 full
complete function 接口调用结束的回调函数(调用成功、失败都会执行)
success function 接口调用成功的回调函数
fail function 接口调用失败的回调函数

函数定义示例

复制代码
/**
 * 关闭所有页面,打开到应用内的某个页面
 */
export function reLaunch(params: {
  /** 页面路径 */
  url: string;
  /** 打开方式,支持全屏full,半屏half;默认全屏full */
  type?: string;
  complete?: () => void;
  success?: (params: null) => void;
  fail?: (params: {
    errorMsg: string;
    errorCode: string | number;
    innerError: {
      errorCode: string | number;
      errorMsg: string;
    };
  }) => void;
}): void;

ty.switchTab

跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面

需引入MiniKit,且在>=2.0.0版本才可使用

参数

Object object

属性 类型 默认值 必填 说明
url string 页面路径
type string 打开方式,支持全屏 full,半屏 half;默认全屏 full
complete function 接口调用结束的回调函数(调用成功、失败都会执行)
success function 接口调用成功的回调函数
fail function 接口调用失败的回调函数

函数定义示例

复制代码
/**
 * 跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面
 */
export function switchTab(params: {
  /** 页面路径 */
  url: string;
  /** 打开方式,支持全屏full,半屏half;默认全屏full */
  type?: string;
  complete?: () => void;
  success?: (params: null) => void;
  fail?: (params: {
    errorMsg: string;
    errorCode: string | number;
    innerError: {
      errorCode: string | number;
      errorMsg: string;
    };
  }) => void;
}): void;

👉 立即开发

相关推荐
用户479492835691511 分钟前
记住这张时间线图,你再也不会乱用 useEffect / useLayoutEffect
前端·react.js
咬人喵喵24 分钟前
14 类圣诞核心 SVG 交互方案拆解(附案例 + 资源)
开发语言·前端·javascript
问君能有几多愁~37 分钟前
C++ 日志实现
java·前端·c++
咬人喵喵38 分钟前
CSS 盒子模型:万物皆是盒子
前端·css
2401_8603195244 分钟前
DevUI组件库实战:从入门到企业级应用的深度探索,如何快速应用各种组件
前端·前端框架
韩曙亮1 小时前
【Web APIs】元素滚动 scroll 系列属性 ② ( 右侧固定侧边栏 )
前端·javascript·bom·window·web apis·pageyoffset
珑墨1 小时前
【浏览器】页面加载原理详解
前端·javascript·c++·node.js·edge浏览器
FreeBuf_1 小时前
Next.js 发布扫描工具:检测并修复受 React2Shell 漏洞(CVE-2025-66478)影响的应用
开发语言·javascript·ecmascript
LYFlied2 小时前
在AI时代,前端开发者如何构建全栈开发视野与核心竞争力
前端·人工智能·后端·ai·全栈
用户47949283569152 小时前
我只是给Typescript提个 typo PR,为什么还要签协议?
前端·后端·开源