index.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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: '',
  9. component: () => import('../views/index.vue'),
  10. },
  11. // 登录
  12. {
  13. path: '/login',
  14. name: 'login',
  15. meta: { title: '登录', subSite: true },
  16. component: () => import('../views/login.vue'),
  17. },
  18. // 注册
  19. {
  20. path: '/register',
  21. meta: { title: '注册', subSite: true },
  22. component: () => import('../views/register.vue'),
  23. },
  24. // 新闻动态
  25. {
  26. path: '/news/index',
  27. meta: { title: '新闻动态', subSite: true },
  28. component: () => import('../views/news/index.vue'),
  29. },
  30. // 新闻动态列表+详情
  31. {
  32. path: '/news/listDetail',
  33. meta: { title: '新闻详情', subSite: true },
  34. component: () => import('../views/news/listDetail.vue'),
  35. },
  36. // 计算服务
  37. {
  38. path: '/service/index',
  39. meta: { title: '计算服务', subSite: true },
  40. component: () => import('../views/service/index.vue'),
  41. },
  42. // 计算服务-详情
  43. {
  44. path: '/service/detail',
  45. meta: { title: '计算服务', subSite: true },
  46. component: () => import('../views/service/detail.vue'),
  47. },
  48. // 交流互动
  49. {
  50. path: '/communication/index',
  51. meta: { title: '交流互动', subSite: true },
  52. component: () => import('../views/communication/index.vue'),
  53. },
  54. //交流互动列表详情
  55. {
  56. path: '/communication/list',
  57. meta: { title: '交流互动列表详情', subSite: true },
  58. component: () => import('../views/communication/list.vue'),
  59. },
  60. //发布需求
  61. {
  62. path: '/demand/demand',
  63. meta: { title: '发布需求', subSite: true },
  64. component: () => import('../views/demand/demand.vue'),
  65. },
  66. //成果展示
  67. {
  68. path: '/achievement/index',
  69. name: '平台建设',
  70. component: () => import('../views/achievement/index.vue'),
  71. },
  72. // 党建学苑
  73. {
  74. path: '/partisan/index',
  75. name: '党建学苑',
  76. meta: { title: '党建学苑', subSite: true },
  77. component: () => import('../views/partisan/index.vue'),
  78. },
  79. // 党建学苑-列表详情
  80. {
  81. path: '/partisan/listDetail',
  82. name: '党建学苑',
  83. meta: { title: '党建学苑', subSite: true },
  84. component: () => import('../views/partisan/listDetail.vue'),
  85. },
  86. // 个人中心
  87. {
  88. path: '/pcenter/index',
  89. name: 'pcenter_center',
  90. component: () => import('../views/pcenter/index.vue'),
  91. },
  92. ];
  93. const router = new VueRouter({
  94. mode: 'history',
  95. base: process.env.NODE_ENV === 'development' ? '' : process.env.VUE_APP_ROUTER,
  96. routes,
  97. });
  98. router.beforeEach((to, form, next) => {
  99. if (to.name === 'pcenter_center') {
  100. store.commit('setUser');
  101. if (to.name === 'login') {
  102. next();
  103. return;
  104. }
  105. let user = store.state.user;
  106. if (user) {
  107. next();
  108. }
  109. //下面是没登录的情况,需要跳转页面到用户未登录页
  110. else next({ name: 'login' });
  111. } else {
  112. store.commit('setUser');
  113. next();
  114. }
  115. });
  116. export default router;