Uniapp 编辑后的代码如何增加tabBar链接
想要增加链接没有源码的情况下只能从监听和注入了 。
找到编译后的tabBar代码一般在index.xxxx.js里
增加一个{pagePath:"pages/service/service",text:"客服",iconPath:"static/images/ico_foot3.png",selectedIconPath:"static/images/ico_foot3.png",redDot:!1,badge:""}
之后在 index.html 里增加一个检测函数
// 保存原始的 switchTab 方法
const originalSwitchTab = uni.switchTab;
// 重写 switchTab
uni.switchTab = function(options) {
// 判断是否是客服页面的跳转
if (options.url.includes('pages/service/service') || options.url.includes('fromTabBar=service')) {
// 使用 navigateTo 替代 switchTab 没有问题就可以跳转了
window.location.href = "https://www.example.com";
return;
}
// 其他情况走原始逻辑
originalSwitchTab(options);
};