uni.navigateTo(options)
保留当前页面,跳转到应用内的某个页面
参数
名称 | 类型 | 必填 | 默认值 | 描述 |
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 | 否 | - | 接口调用结束的回调函数(调用成功、失败都会执行) |
|
NavigateToFail 的属性值
名称 | 类型 | 必备 | 默认值 | 描述 |
errCode | number | 是 | - | 路由错误码 - 4: 框架内部异常 |
errSubject | string | 是 | - | 统一错误主题(模块)名称 |
data | any | null | 否 | - | 错误信息中包含的数据 |
cause | Error | null | 否 | - | 源错误信息,可以包含多个错误,详见SourceError |
errMsg | string | 是 | - | - |
AsyncApiResult 的属性值
名称 | 类型 | 必备 | 默认值 | 描述 |
errMsg | string | 是 | - | - |
NavigateToOptions 兼容性
| 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 |
返回值
navigateTo 兼容性
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 |
返回值
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 |
返回值
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 |
返回值
switchTab 兼容性
Android | iOS | web |
√ | 4.11 | 4.0 |
参见
相关 Bug
uni.navigateBack(options?)
关闭当前页面,返回上一页面或多级页面
参数
名称 | 类型 | 必填 | 默认值 | 描述 |
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 | 否 | - | 接口调用结束的回调函数(调用成功、失败都会执行) |
|
NavigateBackFail 的属性值
名称 | 类型 | 必备 | 默认值 | 描述 |
errCode | number | 是 | - | - |
errSubject | string | 是 | - | 统一错误主题(模块)名称 |
data | any | null | 否 | - | 错误信息中包含的数据 |
cause | Error | null | 否 | - | 源错误信息,可以包含多个错误,详见SourceError |
errMsg | string | 是 | - | - |
AsyncApiResult 的属性值
名称 | 类型 | 必备 | 默认值 | 描述 |
errMsg | string | 是 | - | - |
NavigateBackOptions 兼容性
| 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 |
返回值
navigateBack 兼容性
Android | iOS | web |
√ | 4.11 | 4.0 |
参见
相关 Bug
示例
hello uni-app x
通用类型
GeneralCallbackResult
名称 | 类型 | 必备 | 默认值 | 描述 |
errMsg | string | 是 | - | 错误信息 |
页面跳转与参数传递
A页面跳转到B页面时,有两种方式给B页面传递信息:
- A页面跳转时,B页面的URL中通过?param1=param1value¶m2=param2value方式传递,然后B页面在Onload里接收参数。详见页面onLoad生命周期
- 通过eventbus,详见uni.$on、uni.$emit等API
Bug & Tips
navigateTo
, redirectTo
只能打开非 tabBar 页面。 switchTab
只能打开 tabBar
页面。 reLaunch
可以打开任意页面。 - 页面底部的
tabBar
由页面决定,即只要是定义为 tabBar
的页面,底部都有 tabBar
。 - 不能在首页
onReady
之前进行页面跳转。