小程序跳转页面几种方式

参考官方文档:路由
https://developers.weixin.qq.com/miniprogram/dev/api/route/wx.switchTab.html

//保留当前页面,跳转到应用内的某个页面
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);
}

小程序搜索优化指南

猜你喜欢

转载自blog.csdn.net/qq_45467083/article/details/106439982