微信小程序跳转 TAB 页:wx.switchTab: url 不支持 queryString

发布时间: 2018-08-23 23:47:29 作者: 大象笔记

使用 navigator 标签跳转 TAB 页面

<navigator url="/pages/site_list/site_list?community_id={{ item.id }}" open-type="switchTab">

报了一个错误:

wx.switchTab: url 不支持 queryString

两种解决方案

我觉得存全局变量更合适一点,因为这个值没有数据落地的必要性

源页面修改为

<view bindtap="go_to_site_list" data-cid="{{ item.id }}">

go_to_site_list(event) {
    app.globalData.community_id_for_switch_tab = event.currentTarget.dataset.cid;
    wx.switchTab({
      url: `/pages/site_list/site_list`,
    })
  }

目标 TAB 页

onShow: function () {
    var community_id = app.globalData.community_id_for_switch_tab;
    console.log(community_id);
    // TODO: DO SOMETHING
    if (community_id) {
      // 处理完成后,清空缓存值
      app.globalData.community_id_for_switch_tab = null;
    }
我是一名山东烟台的开发者,联系作者