1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- import { createRouter, createWebHistory } from 'vue-router'
- import SkeletonPage from '@/views/SkeletonPage.vue'
- const router = createRouter({
- history: createWebHistory(import.meta.env.BASE_URL),
- routes: [
- {
- path: '/login',
- name: 'login',
- component: () => import('@/views/LoginPage.vue'),
- },
- {
- path: '/authorized',
- name: 'Authorized',
- component: SkeletonPage,
- children: [
- {
- path: 'adlist',
- name: 'AdList',
- component: () => import('../views/AdListPage.vue'),
- },
- {
- path: 'originality',
- name: 'Originality',
- component: () => import('../views/OriginalityPage.vue'),
- },
- {
- path: 'advertiser',
- name: 'Advertiser',
- component: () => import('../views/AdvertiserPage.vue'),
- },
- {
- path: 'sourceMaterial',
- name: 'SourceMaterial',
- component: () => import('../views/SourceMaterialPage.vue'),
- },
- {
- path: 'site',
- name: 'Site',
- component: () => import('../views/SitePage.vue'),
- },
- {
- path: 'advertisingSpace',
- name: 'AdvertisingSpace',
- component: () => import('../views/AdvertisingSpacePage.vue'),
- },
- {
- path: 'advertisingSpaceDate',
- name: 'AdvertisingSpaceDate',
- component: () => import('../views/AdvertisingSpaceDatePage.vue'),
- },
- {
- path: 'reportForms',
- name: 'ReportForms',
- component: () => import('../views/ReportFormsPage.vue'),
- },
- {
- path: 'reportSpaceForms',
- name: 'ReportSpaceForms',
- component: () => import('../views/ReportSpaceFormsPage.vue'),
- },
- ],
- },
- ],
- })
- // 路由卫士
- router.beforeEach((to, from, next) => {
- const token = localStorage.getItem('token')
- // 如果是登录页面,直接放行
- if (to.path === '/') {
- return next(token ? '/authorized/originality' : '/login')
- }
- if (to.path === '/login') return next()
- // 如果不是登录页面,判断是否登录,如果登录,直接放行,否则跳转到登录页面
- if (token) return next()
- next('/login')
- })
- export default router
|