import { createRouter, createWebHistory } from 'vue-router' import { useLoginStore } from '@/stores/user-info-store' const router = createRouter({ history: createWebHistory(import.meta.env.BASE_URL), routes: [ { path: '/:pathMatch(.*)*', name: 'not-found', redirect: '/home' }, { path: '/login', name: '登录', component: () => import('@/views/login/login.vue'), }, { path: '/', redirect: '/home', children: [ { path: '/home', name: '首页', component: () => import('@/views/home/home.vue'), }, { path: '/remote-manage', name: '远程管理', component: () => import('@/views/remote-manage/remote-manage.vue'), } ] } ] }) router.beforeEach((to, from, next) => { const loginInfo = useLoginStore().getlogin() const isLogin = loginInfo.isLogin if (to.fullPath !=='/login' && !isLogin) { next('/login') // 重定向登录页 } else { // 如果用户有权限,正常进行导航 next() } }); export default router