tt.redirectTo
基础库 1.0.0 版本开始支持本方法。
关闭当前页面,跳转到应用内的某个页面。不能跳转到 tabBar 页面。
语法
tt.redirectTo(options)
参数说明
options
是 object 类型,属性如下:
属性名 | 类型 | 默认值 | 必填 | 说明 | 最低支持版本 |
---|---|---|---|---|---|
url | string | 是 | 需要跳转的应用内非 tabBar 的页面的路径,路径后可以带参数。参数与路径之间使用?分隔,参数键与参数值用=相连,不同参数用&分隔;如 ‘path?key=value&key2=value2’ | 1.0.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 |
效果示例

扫码体验
请使用字节宿主APP扫码
代码示例
// pages/list
Page({
onItemClick(event) {
const sku = event.target.dataset.sku;
tt.redirectTo({
url: `/pages/detail?sku=${sku}`,
success(res) {
console.log(res);
},
fail(res) {
console.log("redirectTo调用失败");
},
});
},
});
// pages/detail
Page({
onLoad(options) {
console.log(options.sku);
},
});
Bug & Tip
- Tip: 使用 navigator 组件也可以实现一样的功能。
点击纠错
评价此篇文档