|
@@ -242,19 +242,17 @@ const router = createRouter({
|
|
|
|
|
|
|
|
// 导航守卫
|
|
// 导航守卫
|
|
|
router.beforeEach(async (to, from, next) => {
|
|
router.beforeEach(async (to, from, next) => {
|
|
|
-
|
|
|
|
|
- // 检查登录状态
|
|
|
|
|
- const isLoggedIn = localStorage.getItem('isLoggedIn') === 'true'
|
|
|
|
|
-
|
|
|
|
|
// 注册页面始终允许访问,不需要登录状态
|
|
// 注册页面始终允许访问,不需要登录状态
|
|
|
if (to.path === '/register-login') {
|
|
if (to.path === '/register-login') {
|
|
|
next()
|
|
next()
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 检查登录状态
|
|
|
|
|
+ const isLoggedIn = localStorage.getItem('isLoggedIn') === 'true'
|
|
|
// 允许未登录用户访问的页面列表
|
|
// 允许未登录用户访问的页面列表
|
|
|
const allowedPages = Object.keys(loginToHomeMap)
|
|
const allowedPages = Object.keys(loginToHomeMap)
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 如果未登录且不是允许访问的页面,重定向到登录页
|
|
// 如果未登录且不是允许访问的页面,重定向到登录页
|
|
|
if (!isLoggedIn && !allowedPages.includes(to.path)) {
|
|
if (!isLoggedIn && !allowedPages.includes(to.path)) {
|
|
|
next('/login')
|
|
next('/login')
|
|
@@ -277,8 +275,6 @@ router.beforeEach(async (to, from, next) => {
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 注册页面已经在前面处理过,这里不需要再处理
|
|
|
|
|
-
|
|
|
|
|
// 获取当前登录类型
|
|
// 获取当前登录类型
|
|
|
const loginPath = localStorage.getItem('loginPath')
|
|
const loginPath = localStorage.getItem('loginPath')
|
|
|
|
|
|