tt.redirectTo
收藏
我的收藏

基础库 1.0.0 开始支持本方法,这是一个异步方法。​
关闭当前页面,跳转到应用内的某个页面,不能跳转到 tabBar 页面。​

语法​

text
复制
tt.redirectTo(options)

参数说明​

options 为 object 类型,属性如下:​
属性名​
类型​
默认值​
必填​
说明​
最低支持版本​
url​
string​
是​
需要跳转的应用内非 tabBar 的页面的路径,路径后可以带参数,参数与路径之间使用 ? 分隔,参数键与参数值用 = 相连,不同参数用 & 分隔,如 "path?key=value&key2=value2"​
1.0.0​
query​
object​
否​
跳转时需要传递的 query 参数,query 对象中的 key、value 最终会被拼接到 url 中,如 "key1=value1&key2=value2"。请注意,如果 query 对象中的 key 和 url 中的 key 重复将被忽略。​
3.7.0​
success​
function​
否​
接口调用成功的回调函数​
1.0.0​
fail​
function​
否​
接口调用失败的回调函数​
1.0.0​
complete​
function​
否​
接口调用结束的回调函数(调用成功、失败都会执行)​
1.0.0​

回调成功​

object 类型,属性如下:​
属性名​
类型​
说明​
最低支持版本​
errMsg​
string​
"redirectTo:ok"​
1.0.0​

回调失败​

object 类型,属性如下:​
属性名​
类型​
说明​
最低支持版本​
errMsg​
string​
"redirectTo:fail " + 详细错误信息​
1.0.0​

错误说明​

errNo​
errMsg​
说明​
最低支持版本​
20000​
redirectTo:fail params.url should be string, but got undefined​
url 未传​
2.28.0​
20000​
redirectTo:fail params.url should be string, but got ${url}​
url 为非字符串​
2.28.0​
20000​
redirectTo:fail url is invalid​
url 无效​
2.28.0​
21301​
redirectTo:fail top view is null​
当前未打开任何页面​
2.28.0​
21102​
redirectTo:fail Can only jump to non-tab pages​
不允许跳转到 tabBar 页面​
2.28.0​
21200​
redirectTo:fail Full screen player exists​
全屏播放器状态下不允许跳转​
2.28.0​
21500​
redirectTo:fail illegal content found​
未通过敏感词检测​
2.28.0​
21500​
redirectTo:fail url "${removeHtmlSuffixFromUrl(url)}" is not in app.json​
页面未在 app.json 中配置​
2.28.0​
21500​
redirectTo:fail this page has been blocked​
目标页面被屏蔽​
2.28.0​

扫码体验​

代码示例​

Bug & Tip​

    Tip: 使用 navigator 组件也可以实现同样的功能。​