let needLogin = [
|
|
// "/pages/user/user",
|
|
]
|
|
let list = ["navigateTo"];
|
|
list.forEach(item => { //用遍历的方式分别为,uni.navigateTo,uni.redirectTo,uni.reLaunch,uni.switchTab这4个路由方法添加拦截器
|
|
console.log(item, 'router list item')
|
|
uni.addInterceptor(item, {
|
|
invoke(e) { // 调用前拦截
|
|
|
|
let length = getCurrentPages().length
|
|
|
|
if (length >= 10) {
|
|
uni.showToast({
|
|
title: '页面栈已满,即将回到首页',
|
|
icon: 'none'
|
|
})
|
|
setTimeout(uni.reLaunch, 1000, {
|
|
url: '/pages/index/index'
|
|
})
|
|
return false
|
|
}
|
|
|
|
return true
|
|
},
|
|
fail(err) { // 失败回调拦截
|
|
console.log(err);
|
|
},
|
|
})
|
|
})
|