uni.navigateTo(options)
保留当前页面,跳转到应用内的某个页面
navigateTo 兼容性
Android | iOS | web |
√ | 4.11 | 4.0 |
参数
名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
options | NavigateToOptions | 是 | - | - | - |
名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 | url | string (string.PageURIString) | 是 | - | | 需要跳转的应用内非 tabBar 的页面的路径 , 路径后可以带参数 | 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 | 是 | - | - | - |
返回值
参见
相关 Bug
uni.redirectTo(options)
关闭当前页面,跳转到应用内的某个页面
redirectTo 兼容性
Android | iOS | web |
√ | 4.11 | 4.0 |
参数
名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
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 | 是 | - | - | - |
返回值
参见
相关 Bug
uni.reLaunch(options)
关闭所有页面,打开到应用内的某个页面
reLaunch 兼容性
Android | iOS | web |
√ | 4.11 | 4.0 |
参数
名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
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 | 是 | - | - | - |
返回值
参见
相关 Bug
uni.switchTab(options)
跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面
switchTab 兼容性
Android | iOS | web |
√ | 4.11 | 4.0 |
参数
名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
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 | 是 | - | - | - |
返回值
参见
相关 Bug
uni.navigateBack(options?)
关闭当前页面,返回上一页面或多级页面
navigateBack 兼容性
Android | iOS | web |
√ | 4.11 | 4.0 |
参数
名称 | 类型 | 必填 | 默认值 | 兼容性 | 描述 |
options | NavigateBackOptions | null | 否 | - | - | |
名称 | 类型 | 必备 | 默认值 | 兼容性 | 描述 | delta | number | null | 否 | - | | 返回的页面数,如果 delta 大于现有页面数,则返回到首页 | 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 | 是 | - | - | - |
返回值
参见
相关 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
之前进行页面跳转。