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

文章目录

    使用 navigator 标签跳转 TAB 页面

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

    报了一个错误:

    wx.switchTab: url 不支持 queryString

    两种解决方案

    • queryString 存 storage
    • 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;
        }
    

    关于作者 🌱

    我是来自山东烟台的一名开发者,有感兴趣的话题,或者软件开发需求,欢迎加微信 zhongwei 聊聊,或者关注我的个人公众号“大象工具”, 查看更多联系方式