| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- import Vue from 'vue'
- import VueRouter from 'vue-router'
- import Layout from '@/views/Layout.vue'
- Vue.use(VueRouter)
- const routes = [
- {
- path: '/login',
- name: 'Login',
- component: () => import('@/views/Login.vue')
- },
- {
- path: '/',
- component: Layout,
- redirect: '/dashboard',
- children: [
- {
- path: 'dashboard',
- name: 'Dashboard',
- component: () => import('@/views/Dashboard.vue'),
- meta: { title: '首页' }
- },
- {
- path: 'users',
- name: 'Users',
- component: () => import('@/views/Users.vue'),
- meta: { title: '用户管理' }
- },
- {
- path: 'families',
- name: 'Families',
- component: () => import('@/views/Families.vue'),
- meta: { title: '家庭管理' }
- },
- {
- path: 'children',
- name: 'Children',
- component: () => import('@/views/Children.vue'),
- meta: { title: '孩子管理' }
- },
- {
- path: 'tasks',
- name: 'Tasks',
- component: () => import('@/views/Tasks.vue'),
- meta: { title: '任务管理' }
- },
- {
- path: 'task-templates',
- name: 'TaskTemplates',
- component: () => import('@/views/TaskTemplates.vue'),
- meta: { title: '任务模板' }
- },
- {
- path: 'rewards',
- name: 'Rewards',
- component: () => import('@/views/Rewards.vue'),
- meta: { title: '奖励管理' }
- },
- {
- path: 'points',
- name: 'Points',
- component: () => import('@/views/Points.vue'),
- meta: { title: '积分管理' }
- },
- {
- path: 'package-audit',
- name: 'PackageAudit',
- component: () => import('@/views/PackageAudit.vue'),
- meta: { title: '套餐审核' }
- },
- {
- path: 'guide-packages',
- name: 'GuidePackages',
- component: () => import('@/views/GuidePackages.vue'),
- meta: { title: '指导师套餐' }
- }
- ]
- }
- ]
- const router = new VueRouter({
- mode: 'history',
- base: process.env.BASE_URL,
- routes
- })
- router.beforeEach((to, from, next) => {\n const token = localStorage.getItem('token')\n const role = localStorage.getItem('role')\n // authentication check\n if (to.path !== '/login' && !token) {\n return next('/login')\n }\n // teacher role protection for /guide* routes\n if (to.path.startsWith('/guide') && role !== 'teacher') {\n return next({ path: '/', replace: true })\n }\n return next()\n})
- export default router
|