index.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { createRouter, createWebHistory } from 'vue-router'
  2. import SkeletonPage from '@/views/SkeletonPage.vue'
  3. const router = createRouter({
  4. history: createWebHistory(import.meta.env.BASE_URL),
  5. routes: [
  6. {
  7. path: '/login',
  8. name: 'login',
  9. component: () => import('@/views/LoginPage.vue'),
  10. },
  11. {
  12. path: '/authorized',
  13. name: 'Authorized',
  14. component: SkeletonPage,
  15. children: [
  16. {
  17. path: 'adlist',
  18. name: 'AdList',
  19. component: () => import('../views/AdListPage.vue'),
  20. },
  21. {
  22. path: 'originality',
  23. name: 'Originality',
  24. component: () => import('../views/OriginalityPage.vue'),
  25. },
  26. {
  27. path: 'advertiser',
  28. name: 'Advertiser',
  29. component: () => import('../views/AdvertiserPage.vue'),
  30. },
  31. {
  32. path: 'sourceMaterial',
  33. name: 'SourceMaterial',
  34. component: () => import('../views/SourceMaterialPage.vue'),
  35. },
  36. {
  37. path: 'site',
  38. name: 'Site',
  39. component: () => import('../views/SitePage.vue'),
  40. },
  41. {
  42. path: 'advertisingSpace',
  43. name: 'AdvertisingSpace',
  44. component: () => import('../views/AdvertisingSpacePage.vue'),
  45. },
  46. {
  47. path: 'advertisingSpaceDate',
  48. name: 'AdvertisingSpaceDate',
  49. component: () => import('../views/AdvertisingSpaceDatePage.vue'),
  50. },
  51. {
  52. path: 'reportForms',
  53. name: 'ReportForms',
  54. component: () => import('../views/ReportFormsPage.vue'),
  55. },
  56. {
  57. path: 'reportSpaceForms',
  58. name: 'ReportSpaceForms',
  59. component: () => import('../views/ReportSpaceFormsPage.vue'),
  60. },
  61. ],
  62. },
  63. ],
  64. })
  65. // 路由卫士
  66. router.beforeEach((to, from, next) => {
  67. const token = localStorage.getItem('token')
  68. // 如果是登录页面,直接放行
  69. if (to.path === '/') {
  70. return next(token ? '/authorized/originality' : '/login')
  71. }
  72. if (to.path === '/login') return next()
  73. // 如果不是登录页面,判断是否登录,如果登录,直接放行,否则跳转到登录页面
  74. if (token) return next()
  75. next('/login')
  76. })
  77. export default router