微信小程序navigation跳转问题


<view>
  <navigator url="../index/index">跳转到新页面</navigator>
  <navigator url="../index/index" open-type="redirect">在当前页打开</navigator>
  <navigator url="../index/index" open-type="switchTab">切换到首页Tab</navigator>
</view>

只有最后一个 open-type="switchTab"是有效果的,前面两个没效果,求解答。

阅读 11.6k
2 个回答
找到问题所在了

navigator 导航的问题 导航分三种
a.open-type="navigate" 打开新界面
b.open-type="redirect" 在本界面中打开新界面
c.open-type="switchTab" 控制tab页之间的切换
注意:
1. 所有需要跳转链接的界面必须在app.json中注册
2. a, b只能连接非tabBar中注册占用的页面,不能打开url="../index/index",因为pages/index/index界面是tab页
3. c只能打开app.json中注册过的tab页,也就是被tabBar注册的界面

查了一下文档
navigator的open-type属性 可选值 'navigate'、'redirect'、'switchTab',对应于wx.navigateTo、wx.redirectTo、wx.switchTab的功能

open-type="navigate"等价于API的 wx.navigateTo 而wx.navigateTo的url是需要跳转的应用内非 tabBar 的页面的路径

open-type="redirect"等价于API的 wx.redirectTo 而wx.redirectTo的url是需要跳转的应用内非 tabBar 的页面的路径

open-type="switchTab"等价于API的 wx.switchTab而wx.switchTab的url是需要跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面

所以 你的问题应该是 最后一个switchTab事件触发以后 把前面的页面都关闭了吧 希望可以帮到你

推荐问题