美文网首页
小程序跳转页面几种方式?

小程序跳转页面几种方式?

作者: nCov | 来源:发表于2019-04-27 22:12 被阅读0次
    //保留当前页面,跳转到应用内的某个页面
    wx.navigateTo({
      url: 'home?cid=1'
    })
    
    //关闭当前页面,跳转到应用内的某个页面
    wx.redirectTo({
       url: 'home?cid=1'
    })
    
    //关闭所有页面,打开到应用内的某个页面。
    wx.reLaunch({
      url: 'home?cid=1'
    })
    
    //跳转到 tabBar 页面,并关闭其他所有非 tabBar 页面
    wx.switchTab({
      url: '/home'
    })
    
    关闭当前页面,返回上一页面或多级页面。可通过 [`getCurrentPages`]获取当前的页面栈,决定需要返回几层。
    
    // 此处是A页面
    wx.navigateTo({
      url: 'B?id=1'
    })
    
    // 此处是B页面
    wx.navigateTo({
      url: 'C?id=1'
    })
    
    // 在C页面内 navigateBack,将返回A页面
    wx.navigateBack({
      delta: 2
    })
    

    跳转页面传递数组参数必须序列化

     let  categoryArr=[1,2,3,4,5]
          category = JSON.stringify(categoryArr)        //取子集分类 数组传递需要序列化
         wx.navigateTo({
             url: `../jumpPage/home/?cate= ${category} `,
            })
    

    接收页面也要序列化参数

     onLoad: function (options) {
      let   category = JSON.parse(options.cate);
     console.log(category)
    }
    

    参数值过长接收时候内容不全得问题

    
    //传参
    wx.navigateTo({//wx.redirectTo、wx.reLaunch
        url: '../details/details?id=' + encodeURIComponent(id)
    
    接收
    onLoad(options) {
        var id = decodeURIComponent(options.id);
    }
    

    相关文章

      网友评论

          本文标题:小程序跳转页面几种方式?

          本文链接:https://www.haomeiwen.com/subject/zgmlnqtx.html