wx.navigateToMiniProgram 实现跳转。
Page({
onLoad(options) {
// 1. 接收中转参数
const targetAppId = options.target_appid;
const targetPath = options.target_path ? decodeURIComponent(options.target_path) : '';
const targetQuery = options.target_query ? decodeURIComponent(options.target_query) : '';
// 2. 拼接完整路径 (如果包含 query)
let finalPath = targetPath;
if (targetQuery) {
finalPath += (finalPath.includes('?') ? '&' : '?') + targetQuery;
}
// 3. 执行跳转
if (targetAppId) {
wx.navigateToMiniProgram({
appId: targetAppId,
path: finalPath,
success(res) {
console.log('跳转成功');
},
fail(err) {
console.error('跳转失败', err);
wx.showModal({
title: '跳转失败',
content: '无法打开目标小程序,请重试',
showCancel: false
});
}
});
}
}
})