当页面累计10条时,会不能跳转,所以需要自己封装一个方法,当有重复的页面存在时,直接跳转
//页面跳转, type =='redirectTo' 是关闭当前页面跳转
export function navigateToBack(url, type) {
let navIndex = -1;
let str = '';
getCurrentPages().map((item, index) => {
let i = url.indexOf("/")
str = url.substring(i + 1, url.length);
let j = str.lastIndexOf("?")
if (j > -1) {
str = str.substring(0, j);
}
str = str.substring(0, j);
console.log(item.route);
console.log(str);
if (item.route == str) {
navIndex = index;
}
})
console.log(getCurrentPages());
if (navIndex >= 0) {
wx.navigateBack({
delta: getCurrentPages().length - navIndex - 1
})
} else {
if (type == 'redirectTo') {
wx.redirectTo({
url: url
})
} else {
wx.navigateTo({
url: url
})
}
}
}