路径参数中含有参数传递前先编码

路径参数中含有参数传递前先编码

直接传参,会去掉路径参数中?及后面的部分,传递前先对路径参数编码,接收时解码

下面例子中,路径参数:/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
  },
原文地址:https://www.cnblogs.com/qq254980080/p/12298150.html