import Vue from 'vue'
import Router from 'vue-router'
import TeacherRouter from './teacherRouter'
import AppRouter from './appRouter'
import AuditionRouter from './auditionRouter'


Vue.use(Router)

let defaultRouter = [
  {
    path: '/',
    redirect: {
      name: 'business'
    }
  }, {
    path: '/queryFortuneBag',
    name: 'FortuneBag',
    component: () => import(/* webpackChunkName:'CallNames'*/'@/views/teacher/queryList/queryFortuneBag'),
    meta: {
      descrition: '页面查看',
      weight: 1 // 页面权重
    }
  },
  {
    path: '/queryActiveList',
    name: 'ActiveList',
    component: () => import(/* webpackChunkName:'CallNames'*/'@/views/teacher/queryList/queryActiveList'),
    meta: {
      descrition: '页面查看',
      weight: 1 // 页面权重
    }},
    {
      path: '/guide',
      name: 'guide',
      component: () => import(/* webpackChunkName:'CallNames'*/'@/views/rules/guide'),
      meta: {
        descrition: '投屏引导',
        weight: 1 // 页面权重
      }}
]

defaultRouter = defaultRouter.concat(TeacherRouter)
                             .concat(AppRouter)
                             .concat(AuditionRouter)

const router = new Router({
  // mode: 'history',
  base: process.env.BASE_URL,
  routes: defaultRouter,
  scrollBehavior () {
    return { x: 0, y: 0 }
  }
})
router.onError((error) => {
  const pattern = /Loading chunk (\d)+ failed/g;
  const isChunkLoadFailed = error.message.match(pattern);
  const targetPath = router.history.pending.fullPath;
  if (isChunkLoadFailed) {
    router.replace(targetPath);
  }
})

export default router
