小程序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;

👉 立即开发。

相关推荐
feixing_fx10 分钟前
CSS Grid 入门:二维布局时代的降维打击
前端·css·前端框架·css3
Lank_M16 分钟前
JPG的8×8块里只要有条边,白底就保不住255
前端
coding漫漫长路18 分钟前
主图纯白检测,阈值放宽到250会放过252的底
前端
计算机魔术师19 分钟前
藏了八个月没被当漏洞的洞,AI红队一晚上翻出来了
前端
用户831348593069821 分钟前
Vue3 v-for:常用用法与开发高频坑点
前端·javascript·vue.js
用户6210075870224 分钟前
Web 3D 开发实践:BIM+GIS 融合需要解决哪些技术问题?
前端·three.js
志尊宝25 分钟前
AI原生前端开发(017):端侧AI与Vue 3结合实战
前端·人工智能·prompt·1024·ai-native
钱栈up26 分钟前
配料秤料位查出来是负数——IoTDB存的是周期增量,我却在拿首尾相减
前端·数据库
Funlang27 分钟前
fun-ui 开源:把浏览器界面接回来
前端·javascript
特立独行的猫A31 分钟前
一份代码,多端产物:仓颉语言的cj-tauri 框架开发桌面和鸿蒙应用指南
前端