微信小程序页面跳转失败的原因可能是:1:检查你跳转的地址是否有误;2:检查你要跳转的地址是否在app.js中注册过;3:当你跳转的地址位于TabBar中时,要使用wx.switchTab来跳转页。 接下来总结一下跳转的方法: 1.API跳转 wx.navigateTo({...}) wx.redirectTo({...}) wx.switchTab({...}) wx.reLanch({...})
(1) wx.navigateTo({...}) 不会销毁当前页面,仅仅是将其hide,使用wx.navigateBack可以返回到原页面。 注意:调用navigateTo 跳转时,调用该方法的页面会被加入堆栈中 // 关闭当前页面,返回上一页面或多级页面。可通过 getCurrentPages() 获取当前的页面栈,决定需要返回几层。
wx.navigateTo({
url: 'page/home/home' // 页面 A
})
wx.navigateTo({
url: 'page/detail/detail' // 页面 B
})
// 跳转到页面 A
wx.navigateBack({
delta: 2
}) (2)wx.redirectTo({...}) 关闭当前页面,跳转到应用内对应的某个页面 (3) wx.switchTab({...}) 跳转到tabBar页面(在app.json中注册过的tabBar页面),同事关闭其他非tabBar页面 (4) wx.reLanch({...}) 关闭所有页面,打开到应用内的某个页面。 2.wxml页面组件跳转(<navigator>) // navigator 组件默认的 open-type 为 navigate
<navigator url="/page/navigate/navigate" hover-class="navigator-hover">跳转到新页面</navigator>
// redirect 对应 API 中的 wx.redirect 方法
<navigator url="../../redirect/redirect/redirect" open-type="redirect" hover-class="other-navigator-hover">在当前页打开</navigator>
// switchTab 对应 API 中的 wx.switchTab 方法
<navigator url="/page/index/index" open-type="switchTab" hover-class="other-navigator-hover">切换 Tab</navigator>
// reLanch 对应 API 中的 wx.reLanch 方法
<navigator url="../../redirect/redirect/redirect" open-type="redirect" hover-class="other-navigator-hover">关闭所有页面,打开到应用内的某个页面</navigator>
// navigateBack 对应 API 中的 wx.navigateBack 方法
<navigator url="/page/index/index" open-type="navigateBack" hover-class="other-navigator-hover">关闭当前页面,返回上一级页面或多级页面</navigator> 相关推荐: 微信小程序页面跳转功能 微信小程序开发中navigator页面跳转的介绍 开发微信小程序视频教程 以上就是技术解答—app微信小程序中的页面跳转的详细内容,更多请关注模板之家(www.mb5.com.cn)其它相关文章! |