index.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import Vue from 'vue';
  2. import VueRouter from 'vue-router';
  3. import store from '@/store/index';
  4. Vue.use(VueRouter);
  5. const routes = [
  6. {
  7. path: '/',
  8. name: 'index',
  9. meta: { title: '班级列表', isleftarrow: false },
  10. component: () => import('../views/index.vue'),
  11. },
  12. // 班级首页
  13. {
  14. path: '/home/index',
  15. name: 'home_index',
  16. meta: { title: '班级首页', isleftarrow: true },
  17. component: () => import('../views/home/index.vue'),
  18. },
  19. // 班级首页
  20. {
  21. path: '/home/teacher',
  22. name: 'home_teacher',
  23. meta: { title: '班级首页', isleftarrow: true },
  24. component: () => import('../views/home/teacher.vue'),
  25. },
  26. // 班级名单
  27. {
  28. path: '/class/index',
  29. name: 'class_index',
  30. meta: { title: '班级名单', isleftarrow: true },
  31. component: () => import('../views/class/index.vue'),
  32. },
  33. // 调查问卷
  34. {
  35. path: '/question/index',
  36. name: 'question_index',
  37. meta: { title: '调查问卷', isleftarrow: true },
  38. component: () => import('../views/question/index.vue'),
  39. },
  40. // 个人中心
  41. {
  42. path: '/user/index',
  43. name: 'user_index',
  44. meta: { title: '个人中心', isleftarrow: true },
  45. component: () => import('../views/user/index.vue'),
  46. },
  47. ];
  48. const router = new VueRouter({
  49. routes,
  50. });
  51. router.beforeEach((to, form, next) => {
  52. store.commit('setUser');
  53. store.commit('setClass');
  54. let user = store.state.user;
  55. if (user) {
  56. console.log('已登录');
  57. }
  58. //下面是没登录的情况,需要跳转页面到用户未登录页
  59. else console.log('未登录');
  60. next();
  61. });
  62. export default router;