let list = ["navigateTo", "redirectTo", "reLaunch", "switchTab"]
let routesWhitelist = ['/pages/tabs/classify','/pages/tabs/study','/pages/tabs/mine'] // 可以直接跳转的路由
let routesMap = [] // 必须登录之后才能跳转的路由
// 路由拦截
list.forEach((item)=> {
uni.addInterceptor(item,{ // 添加拦截器
invoke(args) {
let userToken = store.state.user.token
console.log('跳转的参数', args)
if (routesWhitelist.includes(args.url) || !userToken && args.url === '/pages/login/index') {
return true
}
if (!userToken && routesMap.includes(args.url)) {
// uni.showToast({
// title: '您还未登录哦',
// icon: 'error'
// })
uni.reLaunch({
url: '/pages/login/index'
})
return false
}
return true
}
})
})