微信小程序官方的跳转https://developers.weixin.qq.com/miniprogram/dev/api/route/wx.navigateTo.html不过多解释
当小程序将对象作为参数传递时,可以通过转为字符串的方式实现,接收时再对其进行解析
传递
wx.navigateTo({
url: `path?object=${JSON.stringify(object)}
})
解析
const data = JSON.parse(options.object)
提示:不要将参数object先使用变量存起来,然后进行传递,这样写接收的时候无法解析成功object
当传递的参数中的URL中有特殊符号虚将URL转义后进行传递。
当传递的参数中的URL‘?’问号这种特殊符号时,需使用encodeURIComponent() 函数可把字符串作为 URI 组件进行编码再传递。
传递
let link = '/pages/service/serviceConfirm?serviceData=' + encodeURIComponent(JSON.stringify(data));
wx.navigateTo({
url: link,
});
解析
const data = JSON.parse(decodeURIComponent(options.serviceData));