Skip to content

Commit d771a17

Browse files
author
feige996
committed
fix(router): 修改黑名单登录授权策略逻辑
将关于页面的登录授权策略从黑名单改为白名单,并简化路由拦截器中黑名单策略的处理逻辑
1 parent 1bc08c4 commit d771a17

File tree

1 file changed

+4
-13
lines changed

1 file changed

+4
-13
lines changed

src/router/interceptor.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export const navigateToInterceptor = {
7878
}
7979
const redirectUrl = `${LOGIN_PAGE}?redirect=${encodeURIComponent(fullPath)}`
8080

81-
// #region 1/2 需要登录的情况(白名单策略) ---------------------------
81+
// #region 1/2 默认需要登录的情况(白名单策略) ---------------------------
8282
if (isNeedLoginMode) {
8383
// 需要登录里面的 EXCLUDE_LOGIN_PATH_LIST 表示白名单,可以直接通过
8484
if (judgeIsExcludePath(path)) {
@@ -94,27 +94,18 @@ export const navigateToInterceptor = {
9494
return false // 明确表示阻止原路由继续执行
9595
}
9696
}
97-
// #endregion 1/2 需要登录的情况(白名单策略) ---------------------------
97+
// #endregion 1/2 默认需要登录的情况(白名单策略) ---------------------------
9898

99-
// #region 2/2 不需要登录的情况(黑名单策略) ---------------------------
99+
// #region 2/2 默认不需要登录的情况(黑名单策略) ---------------------------
100100
else {
101101
// 不需要登录里面的 EXCLUDE_LOGIN_PATH_LIST 表示黑名单,需要重定向到登录页
102102
if (judgeIsExcludePath(path)) {
103103
FG_LOG_ENABLE && console.log('2 isNeedLogin(黑名单策略) redirectUrl:', redirectUrl)
104-
105-
// 如果当前路由是登录页,那就重定向走
106-
const { path, query } = parseUrlToObj(redirectUrl)
107-
if (path === LOGIN_PAGE) {
108-
console.log('path:', path)
109-
console.log('query:', query)
110-
uni.navigateTo({ url: query.redirect })
111-
return false // 明确表示阻止原路由继续执行
112-
}
113104
uni.navigateTo({ url: redirectUrl })
114105
return false // 修改为false,阻止原路由继续执行
115106
}
116107
}
117-
// #endregion 2/2 不需要登录的情况(黑名单策略) ---------------------------
108+
// #endregion 2/2 默认不需要登录的情况(黑名单策略) ---------------------------
118109
return true // 明确表示允许路由继续执行
119110
},
120111
}

0 commit comments

Comments
 (0)