提交代码
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
import HomeView from '@/views/HomeView.vue'
|
||||
import { hasAdminSession } from '@/api/systemConfig'
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(import.meta.env.BASE_URL),
|
||||
@@ -38,6 +39,12 @@ const router = createRouter({
|
||||
path: '/pay',
|
||||
redirect: { name: 'sample' },
|
||||
},
|
||||
{
|
||||
path: '/system-config',
|
||||
name: 'systemConfig',
|
||||
component: () => import('@/views/SystemConfigView.vue'),
|
||||
meta: { title: '系统参数管理', requiresAdmin: true },
|
||||
},
|
||||
{
|
||||
path: '/:pathMatch(.*)*',
|
||||
redirect: { name: 'home' },
|
||||
@@ -45,6 +52,14 @@ const router = createRouter({
|
||||
],
|
||||
})
|
||||
|
||||
router.beforeEach((to) => {
|
||||
if (to.meta.requiresAdmin && !hasAdminSession()) {
|
||||
return { name: 'home' }
|
||||
}
|
||||
|
||||
return true
|
||||
})
|
||||
|
||||
router.afterEach((to) => {
|
||||
document.title = (to.meta.title as string | undefined) ?? 'LIBS Lab'
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user