import Vue from "vue";
import Router from "vue-router";
Vue.use(Router);

const originalPush = Router.prototype.push;
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};
// 其他路由
let constantRoutes = [
  {
    path: "/index",
    component: () => import("@/views/login/login"),
    meta: {
      title: "otherLogin",
    },
  },
  {
    path: "/",
    redirect: "/index"//redirect: "/studentAnalysisReport"
  },
];
// 学生端分析报告
let studentAnalysisReport = {
  path: "/studentAnalysisReport",
  redirect: "/studentAnalysisReport/list",
  component: () => import("@/views/analysisReport/index"),
  children: [
    {
      path: "/studentAnalysisReport/list", // 报告列表
      meta: {
        title: "分析报告",
      },
      component: () => import("@/views/analysisReport/studentPage/list/mainPage"),
    },
    {
      name: "reportDetails",
      path: "/studentAnalysisReport/reportDetails",
      component: () => import("@/views/analysisReport/studentPage/mainPage"),
      children: [
        {
          path: "scrolReport",
          component: () =>
            import("@/views/analysisReport/studentPage/scrolReport/transcript"),
          meta: {
            title: "学生分析",
          },
        }
      ],
    },
  ],
};
const createRouter = () =>
  new Router({
    mode: "hash",
    routes: [
      ...constantRoutes,
      studentAnalysisReport
    ],
    scrollBehavior(to, from, savedPosition) {
      if (savedPosition) {
        return savedPosition;
      } else {
        return {
          x: 0,
          y: 0,
        };//路由切换时，滚动条回到顶部
      }
    },
  });

let router = createRouter();
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = "慧教研-" + to.meta.title;
  }
  next();
});

export default router;
