原因:传递的参数中本身携带?会被截断
如下:
跳转前js文件
let url="https://cs.test.com?id=5"
wx.navigateTo({
url: `/webview/webpage?url=${url}`,
})
目标页面js文件
onLoad: function (options) {
let url = options.url;
console.log(url);
}
打印发现参数未传递过来
解决办法
跳转前页面js文件
let url=encodeURIComponent("https://cs.test.com?id=5")
wx.navigateTo({
url: `/webview/webpage?url=${url}`,
})
跳转后目标页面js文件
onLoad: function (options) {
let url = decodeURIComponent(options.url);
console.log(url);
}
encodeURIComponent() 对字符进行编码。
decodeURIComponent() 是对相应编码过的字符进行解码
如果navigateTo传递的参数本身携带?,可以使用
encodeURIComponent和decodeURIComponent编解码,否则会被截断,导致?后面的数据无法传递后跳转页面。