You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.2 KiB
JavaScript
60 lines
1.2 KiB
JavaScript
import { createRouter, createWebHistory } from 'vue-router'
|
|
import { useUserStore } from '@/stores/user'
|
|
|
|
const routes = [
|
|
{
|
|
path: '/',
|
|
redirect: '/mes'
|
|
},
|
|
{
|
|
path: '/login',
|
|
name: 'Login',
|
|
component: () => import('@/views/login/index.vue'),
|
|
meta: { title: '登录', noAuth: true }
|
|
},
|
|
{
|
|
path: '/',
|
|
component: () => import('@/layout/MainLayout.vue'),
|
|
children: [
|
|
{
|
|
path: 'mes',
|
|
name: 'Mes',
|
|
component: () => import('@/views/mes/index.vue'),
|
|
meta: { title: 'MES检测', icon: 'Monitor' }
|
|
},
|
|
{
|
|
path: 'home',
|
|
name: 'Home',
|
|
component: () => import('@/views/home/index.vue'),
|
|
meta: { title: '检测页', icon: 'HomeFilled' }
|
|
}
|
|
// 后续在此添加新菜单路由
|
|
]
|
|
}
|
|
]
|
|
|
|
const router = createRouter({
|
|
history: createWebHistory(),
|
|
routes
|
|
})
|
|
|
|
router.beforeEach((to, from, next) => {
|
|
const userStore = useUserStore()
|
|
|
|
document.title = `${to.meta.title || ''} - SOP作业检测系统`
|
|
|
|
if (to.meta.noAuth) {
|
|
next()
|
|
return
|
|
}
|
|
|
|
if (!userStore.isLoggedIn) {
|
|
next({ name: 'Login', query: { redirect: to.fullPath } })
|
|
return
|
|
}
|
|
|
|
next()
|
|
})
|
|
|
|
export default router
|