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

👉 立即开发

相关推荐
爱学习的马喽3 分钟前
React钩子函数完全指南:从useState到useEffect的实战详解与场景剖析
前端·javascript·react.js
abigale0313 分钟前
开发实战 - ego商城 - 7 地址管理模块
前端·uni-app·node.js
焦糖小布丁15 分钟前
泛域名SSL证书:一张证书保护所有子域名,企业网站必选
前端
SamsongSSS15 分钟前
JavaScript逆向Vue处理事件和捕获错误的核心逻辑
前端·javascript·vue.js·逆向
码银15 分钟前
【简易聊天室】使用 HTML、CSS、JavaScript 结合 WebSocket 技术实现
javascript·css·node.js·html
星光一影18 分钟前
悬赏任务平台/拉新地推系统源码
redis·mysql·小程序·php·uniapp·html5
桃子不吃李子22 分钟前
一些工具的使用
javascript·mongodb·node.js
笨笨狗吞噬者1 小时前
【uniapp】解决小程序分包下的json文件编译后生成到主包的问题
前端·uni-app
2501_915918411 小时前
Fiddler抓包工具详解,HTTP/HTTPS抓包、代理设置与调试技巧一站式教程(含实战案例)
http·ios·小程序·https·fiddler·uni-app·webview
IT_陈寒1 小时前
Redis 7个性能优化技巧,让我们的QPS从5k提升到20k+
前端·人工智能·后端