import Vue from 'vue';
import VueRouter from 'vue-router';
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};
Vue.use(VueRouter);
// 科研实力
const scientific = [
  {
    path: '/scientific/mathematics/index',
    meta: { title: '国家数学中心' },
    component: () => import('../views/scientific/mathematics/index.vue'),
  },
  {
    path: '/scientific/laboratory/index',
    meta: { title: '省重点实验室' },
    component: () => import('../views/scientific/laboratory/index.vue'),
  },
  {
    path: '/scientific/laboratory/info',
    meta: { title: '省重点实验室-详细信息' },
    component: () => import('../views/scientific/laboratory/info.vue'),
  },
  {
    path: '/scientific/work/index',
    meta: { title: '院士工作站' },
    component: () => import('../views/scientific/work/index.vue'),
  },
];
// 创新能力
const innovate = [
  {
    path: '/innovate/achieve/index',
    meta: { title: '成果展示' },
    component: () => import('../views/innovate/achieve/index.vue'),
  },
  {
    path: '/innovate/learning/index',
    meta: { title: '学术交流' },
    component: () => import('../views/innovate/learning/index.vue'),
  },
  {
    path: '/innovate/popularization/index',
    meta: { title: '科普活动' },
    component: () => import('../views/innovate/popularization/index.vue'),
  },
  {
    path: '/innovate/service/index',
    meta: { title: '科技服务' },
    component: () => import('../views/innovate/service/index.vue'),
  },
];
// 科技资讯
const science = [
  {
    path: '/science/notice/index',
    meta: { title: '通知通告' },
    component: () => import('../views/science/notice/index.vue'),
  },
  {
    path: '/science/thefront/index',
    meta: { title: '学术前沿' },
    component: () => import('../views/science/thefront/index.vue'),
  },
  {
    path: '/science/investigation/index',
    meta: { title: '调查调研' },
    component: () => import('../views/science/investigation/index.vue'),
  },
  {
    path: '/science/account/index',
    meta: { title: '个人中心' },
    component: () => import('../views/science/account/index.vue'),
  },
];

const web = [
  {
    path: '/',
    meta: { title: '网站首页' },
    component: () => import('../views/index.vue'),
  },
  // 科研实力
  ...scientific,
  // 创新能力
  ...innovate,
  // 科技资讯
  ...science,
];
const routes = [...web];
const router = new VueRouter({
  mode: 'history',
  base: process.env.VUE_APP_ROUTER,
  routes,
});
// router.beforeEach((to, from, next) => {
//   document.title = `${to.meta.title} `;
//   const token = localStorage.getItem('token');
//   // 不带参数
//   if (to.path == '/work/userCenter/index') {
//     if (!token) {
//       next(`/login?path=${to.path}&&type=2`);
//     } else {
//       let user = jwt.decode(token);
//       store.commit('setUser', user, { root: true });
//       next();
//     }
//   } else {
//     let user = jwt.decode(token);
//     store.commit('setUser', user, { root: true });
//     next();
//   }
// });

export default router;
