| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- import { createRouter, createWebHashHistory } from 'vue-router'
- import { useStore } from '../store'
- import LoginPage from '../components/LoginPage.vue'
- import MainLayout from '../components/MainLayout.vue'
- import Dashboard from '../views/Dashboard.vue'
- import RoleManagement from '../views/RoleManagement.vue'
- import VoiceManagement from '../views/VoiceManagement.vue'
- import RecommendationManagement from '../views/RecommendationManagement.vue'
- // 路由守卫
- const requireAuth = (to, from, next) => {
- const store = useStore()
- if (!store.user && to.path !== '/login') {
- next('/login')
- } else {
- next()
- }
- }
- const routes = [
- {
- path: '/login',
- name: 'Login',
- component: LoginPage
- },
- {
- path: '/',
- component: MainLayout,
- beforeEnter: requireAuth,
- children: [
- {
- path: '',
- name: 'Dashboard',
- component: Dashboard
- },
- {
- path: 'roles',
- name: 'RoleManagement',
- component: RoleManagement
- },
- {
- path: 'voices',
- name: 'VoiceManagement',
- component: VoiceManagement
- },
- {
- path: 'recommendations',
- name: 'RecommendationManagement',
- component: RecommendationManagement
- },
- {
- path: 'settings',
- name: 'Settings',
- component: () => import('../views/Settings.vue')
- }
- ]
- },
- {
- path: '/:pathMatch(.*)*',
- redirect: '/login'
- }
- ]
- const router = createRouter({
- history: createWebHashHistory(),
- routes
- })
- export default router
|