import { createRouter, createWebHashHistory, Router } from 'vue-router';
import Auth from '@/views/layout/auth';
const router: Router = createRouter({
  history: createWebHashHistory(),
  routes: [
    {
      path: '/',
      component: Auth,
      children: [
        {
          path: '/lessonCourseware',
          name: 'lessonCourseware',
          component: () => import('@/views/lessonCourseware/index'),
          meta: {
            title: '云课堂'
          }
        },
        {
          path: '/courseList',
          name: 'courseList',
          component: () => import('@/views/courseList/index'),
          meta: {
            title: '课件详情'
          }
        },
        {
          path: '/coursewarePlay',
          name: 'coursewarePlay',
          component: () => import('@/views/coursewarePlay'),
          meta: {
            title: '课程播放'
          }
        },
        {
          path: '/choose-homework',
          name: 'choose-homework',
          component: () => import('@/views/choose-homework'),
          meta: {
            title: '选择练习内容'
          }
        },
        {
          path: '/classify',
          name: 'classify',
          component: () => import('@/views/choose-homework/classify'),
          meta: {
            title: '云练习'
          }
        },
        {
          path: '/music-list/:id',
          component: () => import('@/views/choose-homework/music-list'),
          meta: {
            title: '云练习'
          }
        },
        {
          path: '/classroom-detail',
          component: () => import('@/views/choose-homework/classroom-detail'),
          meta: {
            title: '教材详情'
          }
        },
        {
          path: '/exerciseAfterClass',
          name: 'exerciseAfterClass',
          component: () => import('@/views/exercise-after-class/index'),
          meta: {
            title: '观看视频'
          }
        },
        {
          path: '/login',
          name: 'login',
          component: () => import('@/views/layout/login'),
          meta: {
            isRegister: false
          }
        }
      ]
    }
  ],
  scrollBehavior(to, form, savedPosition) {
    if (savedPosition) {
      return savedPosition;
    } else {
      return { left: 0, top: 0 };
    }
  }
});

// router.onError(error => {
//   if (error instanceof Error) {
//     const isChunkLoadFailed = error.name.indexOf('chunk');
//     const targetPath = router.currentRoute.value.fullPath;
//     console.log(error);
//     if (isChunkLoadFailed) {
//       location.hash = targetPath;
//       window.location.reload();
//     }
//   }
// });

export default router;
