保留当前页面,跳转到应用内的某个页面

# 参数

名称 类型 必填 默认值 描述
options NavigateToOptions - -
名称 类型 必备 默认值 描述
url string (string.PageURIString) - 需要跳转的应用内非 tabBar 的页面的路径 , 路径后可以带参数
animationType string | null - 窗口显示的动画类型
- auto: 自动选择动画效果
- none: 无动画效果
- slide-in-right: 从右侧横向滑动效果
- slide-in-left: 左侧横向滑动效果
- slide-in-top: 从上侧竖向滑动效果
- slide-in-bottom: 从下侧竖向滑动效果
- fade-in: 从透明到不透明逐渐显示效果
- zoom-out: 从小到大逐渐放大显示效果
- zoom-fade-out: 从小到大逐渐放大并且从透明到不透明逐渐显示效果
- pop-in: 从右侧平移入栈动画效果
- UnionType => 'auto' | 'none' | 'slide-in-right' | 'slide-in-left' | 'slide-in-top' | 'slide-in-bottom' | 'fade-in' | 'zoom-out' | 'zoom-fade-out' | 'pop-in'
animationDuration number | null - 窗口显示动画的持续时间,单位为 ms
events any | null - 页面间通信接口,用于监听被打开页面发送到当前页面的数据
success (result: AsyncApiSuccessResult) => void | null - 接口调用成功的回调函数
fail (result: NavigateToFail) => void | null - 接口调用失败的回调函数
complete (result: AsyncApiResult) => void | null - 接口调用结束的回调函数(调用成功、失败都会执行)
名称 类型 必备 默认值 描述
errCode number - 路由错误码 - 4: 框架内部异常
errSubject string - 统一错误主题(模块)名称
data any | null - 错误信息中包含的数据
cause Error | null - 源错误信息,可以包含多个错误,详见SourceError
errMsg string - -
# AsyncApiResult 的属性值
名称 类型 必备 默认值 描述
errMsg string - -
Android iOS web
url 4.11 4.0
animationType x x 4.0
animationDuration x x 4.0
events x x 4.0
success 4.11 4.0
fail 4.11 4.0
complete 4.11 4.0

# 返回值

类型 必备
Promise | null
Android iOS web
4.11 4.0

# 参见

相关 Bug

# uni.redirectTo(options)

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

# 参数

名称 类型 必填 默认值 描述
options RedirectToOptions - -
名称 类型 必备 默认值 描述
url string (string.PageURIString) - 需要跳转的应用内非 tabBar 的页面的路径 , 路径后可以带参数
success (result: AsyncApiSuccessResult) => void | null - 接口调用成功的回调函数
fail (result: RedirectToFail) => void | null - 接口调用失败的回调函数
complete (result: AsyncApiResult) => void | null - 接口调用结束的回调函数(调用成功、失败都会执行)
# RedirectToFail 的属性值
名称 类型 必备 默认值 描述
errCode number - -
errSubject string - 统一错误主题(模块)名称
data any | null - 错误信息中包含的数据
cause Error | null - 源错误信息,可以包含多个错误,详见SourceError
errMsg string - -
# AsyncApiResult 的属性值
名称 类型 必备 默认值 描述
errMsg string - -
# RedirectToOptions 兼容性
Android iOS web
url 4.11 4.0
success 4.11 4.0
fail 4.11 4.0
complete 4.11 4.0

# 返回值

类型 必备
Promise | null

# redirectTo 兼容性

Android iOS web
4.11 4.0

# 参见

相关 Bug

# uni.reLaunch(options)

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

# 参数

名称 类型 必填 默认值 描述
options ReLaunchOptions - -
名称 类型 必备 默认值 描述
url string (string.PageURIString) - 需要跳转的应用内页面路径 , 路径后可以带参数。参数与路径之间使用?分隔,参数键与参数值用=相连,不同参数用&分隔;如 'path?key=value&key2=value2',如果跳转的页面路径是 tabBar 页面则不能带参数
success (result: AsyncApiSuccessResult) => void | null - 接口调用成功的回调函数
fail (result: ReLaunchFail) => void | null - 接口调用失败的回调函数
complete (result: AsyncApiResult) => void | null - 接口调用结束的回调函数(调用成功、失败都会执行)
# ReLaunchFail 的属性值
名称 类型 必备 默认值 描述
errCode number - -
errSubject string - 统一错误主题(模块)名称
data any | null - 错误信息中包含的数据
cause Error | null - 源错误信息,可以包含多个错误,详见SourceError
errMsg string - -
# AsyncApiResult 的属性值
名称 类型 必备 默认值 描述
errMsg string - -
# ReLaunchOptions 兼容性
Android iOS web
url 4.11 4.0
success 4.11 4.0
fail 4.11 4.0
complete 4.11 4.0

# 返回值

类型 必备
Promise | null

# reLaunch 兼容性

Android iOS web
4.11 4.0

# 参见

相关 Bug

# uni.switchTab(options)

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

# 参数

名称 类型 必填 默认值 描述
options SwitchTabOptions - -
名称 类型 必备 默认值 描述
url string (string.PageURIString) - 需要跳转的 tabBar 页面的路径,路径后不能带参数
success (result: AsyncApiSuccessResult) => void | null - 接口调用成功的回调函数
fail (result: SwitchTabFail) => void | null - 接口调用失败的回调函数
complete (result: AsyncApiResult) => void | null - 接口调用结束的回调函数(调用成功、失败都会执行)
# SwitchTabFail 的属性值
名称 类型 必备 默认值 描述
errCode number - -
errSubject string - 统一错误主题(模块)名称
data any | null - 错误信息中包含的数据
cause Error | null - 源错误信息,可以包含多个错误,详见SourceError
errMsg string - -
# AsyncApiResult 的属性值
名称 类型 必备 默认值 描述
errMsg string - -
# SwitchTabOptions 兼容性
Android iOS web
url 4.11 4.0
success 4.11 4.0
fail 4.11 4.0
complete 4.11 4.0

# 返回值

类型 必备
Promise | null

# switchTab 兼容性

Android iOS web
4.11 4.0

# 参见

相关 Bug

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

# 参数

名称 类型 必填 默认值 描述
options NavigateBackOptions | null -
名称 类型 必备 默认值 描述
delta number | null - 返回的页面数,如果 delta 大于现有页面数,则返回到首页
animationType string | null - 窗口关闭的动画类型
- auto: 自动选择动画效果
- none: 无动画效果
- slide-out-right: 横向向右侧滑出屏幕动画
- slide-out-left: 横向向左侧滑出屏幕动画
- slide-out-top: 竖向向上侧滑出屏幕动画
- slide-out-bottom: 竖向向下侧滑出屏幕动画
- fade-out: 从不透明到透明逐渐隐藏动画
- zoom-in: 从大逐渐缩小关闭动画
- zoom-fade-in: 从大逐渐缩小并且从不透明到透明逐渐隐藏关闭动画
- pop-out: 从右侧平移出栈动画效果
- UnionType => 'auto' | 'none' | 'slide-out-right' | 'slide-out-left' | 'slide-out-top' | 'slide-out-bottom' | 'fade-out' | 'zoom-in' | 'zoom-fade-in' | 'pop-out'
animationDuration number | null - 窗口关闭动画的持续时间,单位为 ms
success (result: AsyncApiSuccessResult) => void | null - 接口调用成功的回调函数
fail (result: NavigateBackFail) => void | null - 接口调用失败的回调函数
complete (result: AsyncApiResult) => void | null - 接口调用结束的回调函数(调用成功、失败都会执行)
名称 类型 必备 默认值 描述
errCode number - -
errSubject string - 统一错误主题(模块)名称
data any | null - 错误信息中包含的数据
cause Error | null - 源错误信息,可以包含多个错误,详见SourceError
errMsg string - -
# AsyncApiResult 的属性值
名称 类型 必备 默认值 描述
errMsg string - -
Android iOS web
delta 4.11 4.0
animationType x x 4.0
animationDuration x x 4.0
success x 4.0
fail 4.11 4.0
complete 4.11 4.0

# 返回值

类型 必备
Promise | null
Android iOS web
4.11 4.0

# 参见

相关 Bug

# 示例

hello uni-app x

Template

Script

<template>
  <!-- #ifdef APP -->
  <scroll-view style="flex: 1">
  <!-- #endif -->
    <view>
      <page-head title="navigate"></page-head>
      <view class="uni-padding-wrap uni-common-mt uni-common-mb">
        <view class="direction-row">
          <text class="label">onLoad触发时间戳:</text>
          <text>{{ onLoadTime }}</text>
        </view>
        <view class="direction-row">
          <text class="label">onShow触发时间戳:</text>
          <text>{{ onShowTime }}</text>
        </view>
        <view class="direction-row">
          <text class="label">onReady触发时间戳:</text>
          <text>{{ onReadyTime }}</text>
        </view>
        <view class="direction-row">
          <text class="label">onHide触发时间戳:</text>
          <text>{{ onHideTime }}</text>
        </view>
        <view class="direction-row">
          <text class="label">onBackPress触发时间戳:</text>
          <text>见控制台</text>
        </view>
        <view class="direction-row">
          <text class="label">onUnload触发时间戳:</text>
          <text>见控制台</text>
        </view>
        <view class="uni-btn-v">
          <button @tap="navigateTo" class="uni-btn">
            跳转新页面,并传递数据
          </button>
          <button @tap="navigateBack" class="uni-btn">返回上一页</button>
          <button @tap="redirectTo" class="uni-btn">在当前页面打开</button>
          <button @tap="switchTab" class="uni-btn">切换到模板选项卡</button>
          <button @tap="reLaunch" class="uni-btn">
            关闭所有页面,打开首页
          </button>
          <button @tap="navigateToErrorPage" class="uni-btn">
            打开不存在的页面
          </button>
        </view>
      </view>
    </view>
  <!-- #ifdef APP -->
  </scroll-view>
  <!-- #endif -->
</template>



<style>
  .direction-row {
    flex-direction: row;
  }

  .label {
    width: 190px;
  }
</style>

# 通用类型

# GeneralCallbackResult

名称 类型 必备 默认值 描述
errMsg string - 错误信息

# 页面跳转与参数传递

A页面跳转到B页面时,有两种方式给B页面传递信息:

  1. A页面跳转时,B页面的URL中通过?param1=param1value&param2=param2value方式传递,然后B页面在Onload里接收参数。详见页面onLoad生命周期
  2. 通过eventbus,详见uni.$on、uni.$emit等API

# Bug & Tips

  • navigateTo, redirectTo 只能打开非 tabBar 页面。
  • switchTab 只能打开 tabBar 页面。
  • reLaunch 可以打开任意页面。
  • 页面底部的 tabBar 由页面决定,即只要是定义为 tabBar 的页面,底部都有 tabBar
  • 不能在首页 onReady 之前进行页面跳转。