大屏页面初始化
This commit is contained in:
@@ -5,7 +5,6 @@ import Layout from '@/components/Layout/index.vue'
|
||||
import Dashboard from '@/views/desktop/index.vue'
|
||||
import bigScreen from '@/views/screen/index.vue'
|
||||
|
||||
// 扫描规则保持不变
|
||||
const modules = import.meta.glob('../views/**/index.vue', {
|
||||
eager: false,
|
||||
import: 'default'
|
||||
@@ -47,16 +46,16 @@ const generateRoutes = () => {
|
||||
}
|
||||
|
||||
const routes = [
|
||||
{
|
||||
path: '/',
|
||||
redirect: '/login'
|
||||
},
|
||||
{
|
||||
path: '/login',
|
||||
name: 'Login',
|
||||
component: Login,
|
||||
meta: { isPublic: true }
|
||||
},
|
||||
{
|
||||
path: '/',
|
||||
redirect: '/login'
|
||||
},
|
||||
{
|
||||
path: '/bigScreen',
|
||||
name: 'bigScreen',
|
||||
@@ -64,12 +63,12 @@ const routes = [
|
||||
meta: { requiresAuth: true }
|
||||
},
|
||||
{
|
||||
path: '/',
|
||||
path: '/layout',
|
||||
component: Layout,
|
||||
meta: { requiresAuth: true },
|
||||
children: [
|
||||
{
|
||||
path: 'dashboard',
|
||||
path: '/dashboard',
|
||||
name: 'Dashboard',
|
||||
component: Dashboard
|
||||
},
|
||||
@@ -91,21 +90,30 @@ const router = createRouter({
|
||||
}
|
||||
})
|
||||
|
||||
// 优化路由守卫逻辑:更健壮的登录校验
|
||||
router.beforeEach((to, from, next) => {
|
||||
// 公开页面直接放行
|
||||
if (to.meta.isPublic) {
|
||||
next()
|
||||
return
|
||||
}
|
||||
|
||||
// 非公开页面校验token
|
||||
try {
|
||||
const token = localStorage.getItem('token')
|
||||
if (token && token.trim() !== '') {
|
||||
next();
|
||||
// 严格校验token有效性
|
||||
if (token && typeof token === 'string' && token.trim() !== '') {
|
||||
next()
|
||||
} else {
|
||||
next({ path: '/login', query: { redirect: to.fullPath } });
|
||||
next({
|
||||
path: '/login',
|
||||
query: { redirect: to.fullPath },
|
||||
replace: true // 替换历史记录,避免回退问题
|
||||
})
|
||||
}
|
||||
} catch (error) {
|
||||
next('/login');
|
||||
console.error('路由守卫校验token失败:', error)
|
||||
next({ path: '/login', replace: true })
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user