import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '@/views/Home/index'
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
    meta: { title: "列表页面" },
    children: [
      {
        path: "",
        name: 'Index',
        component: () => import("@/views/Home/pages/index"),
        meta: {
          keepAlive: true,
          title: '首页'
        }
      },
      {
        path: "knowledgebase",
        name: 'knowledgebase',
        component: () => import("@/views/Home/pages/knowledge_base"),
        meta: {
          title: '知识库'
        }
      },
      {
        path: "practice",
        name: 'practice',
        component: () => import("@/views/Home/pages/practice"),
        meta: {
          title: '习题练习'
        }
      },
      {
        path: "examinationrecord",
        name: 'examinationrecord',
        component: () => import("@/views/Home/pages/examination_record"),
        meta: {
          title: '考试记录'
        }
      },
      {
        path: "formalexamination",
        name: 'formalexamination',
        component: () => import("@/views/Home/pages/formal_examination"),
        meta: {
          title: '正式考试'
        }
      },
      {
        path: "mockexamination",
        name: 'mockexamination',
        component: () => import("@/views/Home/pages/mock_examination"),
        meta: {
          title: '模拟考试'
        }
      },
      {
        path: "wrongquestion",
        name: 'wrongquestion',
        component: () => import("@/views/Home/pages/wrongquestion"),
        meta: {
          title: '错题集'
        }
      }
    ]
  },
  {
    path: "/mocktestreport",
    name: 'Mocktestreport',
    component: () => import("@/views/Home/pages/mock_test_report"),
    meta: {
      title: '考试报告'
    }
  },
  {
    path: '/exam',
    name: 'Exam',
    component: () => import("@/views/Exam/index"),
    meta: { title: "习题练习页面" }
  },
  {
    path: '/mockexam',
    name: 'Mockexam',
    component: () => import("@/views/Exam/mock_exam"),
    meta: { title: "模拟考试考试页面" }
  },
  {
    path: '/formalexam',
    name: 'Formalexam',
    component: () => import("@/views/Exam/formal_exam"),
    meta: { title: "正式考试考试页面" }
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/Login/index.vue'),
    meta: { title: "登录页面" }
  },
  {
    path: '*',
    name: '404',
    component: () => import('@/views/PageError/404.vue'),
    meta: { title: "404" }
  }
]

const router = new VueRouter({
  // mode: "history",
  routes
})
router.beforeEach((to, from, next) => {
  let token = sessionStorage.getItem("token");
  if (to.path != '/login' && !token) next({ path: "/login" });
  next();
})
export default router
