修复首次打开小程序未自动跳转授权页面的问题
问题原因: 1. 授权页面pages/auth/auth未在pages.json中注册 2. uni.redirectTo无法跳转到未注册的页面 3. 缺少详细的日志输出 解决方案: 1. 在pages.json中添加授权页面配置 - 路径:pages/auth/auth - 导航栏标题:授权登录 - 导航栏背景色:#10B981(绿色) - 导航栏文字颜色:white 2. 优化App.vue跳转逻辑 - 使用uni.navigateTo替代uni.redirectTo - 添加navigateTo失败后的redirectTo备用方案 - 添加详细的console.log日志输出 - 在跳转前设置hasShownAuth标记 3. 增强调试信息 - 输出用户授权状态检查结果 - 输出hasUserInfo和hasShownAuth的值 - 输出跳转成功/失败的详细信息 测试要点: - 首次打开小程序自动跳转到授权页面 - 授权页面正常显示 - 授权成功后跳转到首页
This commit is contained in:
1 parent
28848d541d
commit
a7efc92f2a
2 files changed
+23
-1
No files matched your search
@@ -15,17 +15,31 @@ export default {
|
||||
const userInfo = uni.getStorageSync('userInfo')
|
||||
const hasShownAuth = uni.getStorageSync('hasShownAuth')
|
||||
|
||||
console.log('检查用户授权状态:', {
|
||||
hasUserInfo: !!userInfo,
|
||||
hasShownAuth: hasShownAuth
|
||||
})
|
||||
|
||||
if (!userInfo && !hasShownAuth) {
|
||||
console.log('首次使用,跳转到授权页面')
|
||||
uni.setStorageSync('hasShownAuth', true)
|
||||
setTimeout(() => {
|
||||
uni.redirectTo({
|
||||
uni.navigateTo({
|
||||
url: '/pages/auth/auth',
|
||||
success: () => {
|
||||
console.log('跳转授权页面成功')
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('跳转授权页面失败:', err)
|
||||
uni.redirectTo({
|
||||
url: '/pages/auth/auth',
|
||||
success: () => {
|
||||
console.log('redirectTo跳转授权页面成功')
|
||||
},
|
||||
fail: (err2) => {
|
||||
console.error('redirectTo跳转授权页面也失败:', err2)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}, 500)
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
{
|
||||
"pages": [
|
||||
{
|
||||
"path": "pages/auth/auth",
|
||||
"style": {
|
||||
"navigationBarTitleText": "授权登录",
|
||||
"navigationBarBackgroundColor": "#10B981",
|
||||
"navigationBarTextStyle": "white"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/index/index",
|
||||
"style": {
|
||||
|
||||
Reference in new issue
Block a user