“
let list = ["navigateTo", "redirectTo", "reLaunch", "switchTab"]
list.forEach(item => {
uni.addInterceptor(item, {
invoke(to) {
if (getToken() != '' && getAddressKey() != '') {
if (to.url === loginPage) {
uni.reLaunch({
url: "pages/index"
})
}
return true
} else {
if (checkWhite(to.url) || to.url == '/pages/address') {
return true
} else {
uni.reLaunch({
url: '/pages/login'
})
}
return false
}
},
fail(err) {
console.log(err)
}
})
})
”

- 发布:2023-07-25 17:29
- 更新:2023-07-25 17:29
- 阅读:166
产品分类: uniapp/App
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: 1.1.1
HBuilderX类型: 正式
HBuilderX版本号: 3.8.11
手机系统: Android
手机系统版本号: Android 13
手机厂商: 小米
手机机型: 天机
页面类型: vue
vue版本: vue2
打包方式: 云端
项目创建方式: HBuilderX
操作步骤:
预期结果:
“
let list = ["navigateTo", "redirectTo", "reLaunch", "switchTab"]
list.forEach(item => {
uni.addInterceptor(item, {
invoke(to) {
if (getToken() != '' && getAddressKey() != '') {
if (to.url === loginPage) {
uni.reLaunch({
url: "pages/index"
})
}
return true
} else {
if (checkWhite(to.url) || to.url == '/pages/address') {
return true
} else {
uni.reLaunch({
url: '/pages/login'
})
}
return false
}
},
fail(err) {
console.log(err)
}
})
})
”
“
let list = ["navigateTo", "redirectTo", "reLaunch", "switchTab"]
list.forEach(item => {
uni.addInterceptor(item, {
invoke(to) {
if (getToken() != '' && getAddressKey() != '') {
if (to.url === loginPage) {
uni.reLaunch({
url: "pages/index"
})
}
return true
} else {
if (checkWhite(to.url) || to.url == '/pages/address') {
return true
} else {
uni.reLaunch({
url: '/pages/login'
})
}
return false
}
},
fail(err) {
console.log(err)
}
})
})
”
实际结果:
“
let list = ["navigateTo", "redirectTo", "reLaunch", "switchTab"]
list.forEach(item => {
uni.addInterceptor(item, {
invoke(to) {
if (getToken() != '' && getAddressKey() != '') {
if (to.url === loginPage) {
uni.reLaunch({
url: "pages/index"
})
}
return true
} else {
if (checkWhite(to.url) || to.url == '/pages/address') {
return true
} else {
uni.reLaunch({
url: '/pages/login'
})
}
return false
}
},
fail(err) {
console.log(err)
}
})
})
”
“
let list = ["navigateTo", "redirectTo", "reLaunch", "switchTab"]
list.forEach(item => {
uni.addInterceptor(item, {
invoke(to) {
if (getToken() != '' && getAddressKey() != '') {
if (to.url === loginPage) {
uni.reLaunch({
url: "pages/index"
})
}
return true
} else {
if (checkWhite(to.url) || to.url == '/pages/address') {
return true
} else {
uni.reLaunch({
url: '/pages/login'
})
}
return false
}
},
fail(err) {
console.log(err)
}
})
})
”
bug描述:
打开非 tabbar nvue 页面可能依然显示 tabbar 的Bug