WX页面跳转--路由

//关闭当前页面,返回上一页面或多级页面。可通过 getCurrentPages()获取当前的页面栈,决定需要返回几层。
wx.navigateBack({
    delta:1, //返回的页面数,如果 delta 大于现有页面数,则返回到首页。
    success:function(){}, //接口调用成功的回调函数
    fail:function(){}, //接口调用失败的回调函数
    complete:function(){} //接口调用结束的回调函数(调用成功、失败都会执行)
})
<navigator open-type="navigateBack"/>
//保留当前页面,跳转到应用内的某个页面。但是不能跳到 tabbar 页面。使用wx.navigateBack可以返回到原页面。小程序中页面栈最多十层。
wx.navigateTo({
    url:'path?key=value&key2=value2',
    success:function(){}, //接口调用成功的回调函数
    fail:function(){}, //接口调用失败的回调函数
    complete:function(){} //接口调用结束的回调函数(调用成功、失败都会执行)
})
//注意:目前页面路径最多只能十层。
<navigator open-type="navigateTo"/>
//关闭当前页面,跳转到应用内的某个页面。但是不允许跳转到 tabbar 页面。
wx.redirectTo({
    url:'path?key=value&key2=value2',
    success:function(){}, //接口调用成功的回调函数
    fail:function(){}, //接口调用失败的回调函数
    complete:function(){} //接口调用结束的回调函数(调用成功、失败都会执行)
})
<navigator open-type="redirectTo"/>
//关闭所有页面,打开到应用内的某个页面。
wx.reLaunch({
    url:'path?key=value&key2=value2',
    success:function(){}, //接口调用成功的回调函数
    fail:function(){}, //接口调用失败的回调函数
    complete:function(){} //接口调用结束的回调函数(调用成功、失败都会执行)
})
<navigator open-type="reLaunch"/>
//跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面
wx.switchTab({
    url:'paht',//需要跳转的 tabBar 页面的路径(需在 app.json 的 tabBar字段定义的页面),路径后不能带参数。
    success:function(){}, //接口调用成功的回调函数
    fail:function(){}, //接口调用失败的回调函数
    complete:function(){} //接口调用结束的回调函数(调用成功、失败都会执行)
})
<navigator open-type="switchTab"/>

tips

navigateTo, redirectTo 只能打开非 tabBar 页面。
switchTab 只能打开 tabBar 页面。
reLaunch 可以打开任意页面。
页面底部的 tabBar 由页面决定,即只要是定义为 tabBar 的页面,底部都有 tabBar。
调用页面路由带的参数可以在目标页面的onLoad中获取。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容