路径参数中含有参数传递前先编码
路径参数中含有参数传递前先编码
直接传参,会去掉路径参数中?及后面的部分,传递前先对路径参数编码,接收时解码
下面例子中,路径参数:/pages/job-detail/job-detail?id=1
wx.navigateTo({ url: `/pages/login/login?redirect_url=/pages/job-detail/job-detail?id=1`, })
传递前对路径参数编码:encodeURIComponent
let redirectUrl = encodeURIComponent(`/pages/job-detail/job-detail?id=1`) wx.navigateTo({ url: `/pages/login/login?redirect_url=${redirectUrl}`, })
接收时解码:decodeURIComponent
onLoad: function (options) { const redirectUrl = decodeURIComponent(options.redirect_url) this.data.redirectUrl = redirectUrl },