import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/layout'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    component: Layout,
    children: [
      {
        path: '',
        name: 'Index',
        component: () => import('@/views/Home/HomeIndex.vue'),
        meta: {
          title: '首页'
        }
      },
      {
        path: 'policyadvice',
        name: 'PolicyAdvice',
        component: () => import('@/views/PolicyAdvice/PolicyAdviceIndex.vue'),
        meta: {
          title: '政策咨询'
        }
      },
      {
        path: 'recruitmentemployment',
        name: 'RecruitmentEmploymentIndex',
        component: () =>
          import(
            '@/views/RecruitmentEmployment/RecruitmentEmploymentIndex.vue'
          ),
        meta: {
          title: '招聘就业'
        }
      },
      {
        path: 'cooperativeenterprise',
        name: 'CooperativeEnterpriseIndex',
        component: () =>
          import(
            '@/views/CooperativeEnterprise/CooperativeEnterpriseIndex.vue'
          ),
        meta: {
          title: '合作企业'
        }
      },
      {
        path: 'cooperativecolleges',
        name: 'CooperativeCollegesIndex',
        component: () =>
          import('@/views/CooperativeColleges/CooperativeCollegesIndex.vue'),
        meta: {
          title: '合作院校'
        }
      },
      {
        path: 'skilltraining',
        name: 'SkillTrainingIndex',
        component: () => import('@/views/SkillTraining/SkillTrainingIndex.vue'),
        meta: {
          title: '技能培训'
        }
      },
      {
        path: 'workguide',
        name: 'WorkGuideIndex',
        component: () => import('@/views/WorkGuide/WorkGuideIndex.vue'),
        meta: {
          title: '创业指引'
        }
      },
      {
        path: 'educationpromote',
        name: 'EducationPromoteIndex',
        component: () =>
          import('@/views/EducationPromote/EducationPromoteIndex.vue'),
        meta: {
          title: '学历提升'
        }
      },
      {
        path: 'adaptivetraining',
        name: 'AdaptiveTrainingIndex',
        component: () =>
          import('@/views/AdaptiveTraining/AdaptiveTrainingIndex.vue'),
        meta: {
          title: '适应性培训'
        }
      }
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/Login/LoginIndex.vue'),
    meta: {
      title: '登录'
    }
  }
]

const router = new VueRouter({
  mode: 'history',
  routes
})
router.beforeEach((to, from, next) => {
  /* 路由发生变化修改页面title */
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})

export default router
