import Vue from 'vue';
import VueRouter from 'vue-router';
import HManagement from './HManagement.js'
import SManagement from './SManagement.js';
Vue.use(VueRouter);

Vue.use(VueRouter);
const RouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (to) {
  return RouterPush.call(this, to).catch(err => err)
}
const RouterReplace = VueRouter.prototype.replace
VueRouter.prototype.replace = function replace (to) {
  return RouterReplace.call(this, to).catch(err => err)
}
let routes = [
  {
    path: '/',
    name: 'login',
    component: () => import(/* webpackChunkName: "about" */ '@/views/login/login.vue')
  },
  {
    path: '/accounts',
    name: 'accounts',
    component: () => import(/* webpackChunkName: "about" */ '@/views/select_accounts/index.vue')
  },
  {
    path: '/main',
    name: 'main',
    component: () => import(/* webpackChunkName: "about" */ '@/components/layout/index.vue'),
    redirect: '/home',
    children: [
      {
        path: '/home',
        name: 'home',
        meta: {
          title: '工作台',
          ast_nav:false
        },
        component: () => import(/* webpackChunkName: "about" */ '@/views/homePage/index.vue')
      },
      {
        path: '/mediaStock',
        name: 'mediacenter',
        meta: {
          title: '媒体库',
          ast_nav:true
        },
        component: () => import(/* webpackChunkName: "about" */ '@/views/mediaStock/index.vue')
      },
      {
        path: '/mediaStatistics',
        name: 'mediaStatistics',
        meta: {
          title: '数据统计',
          ast_nav:true
        },
        component: () => import(/* webpackChunkName: "about" */ '@/views/mediaStatistics/index.vue')
      }]
  }
];

routes[2].children = [...routes[2].children,...HManagement,...SManagement]

const router = new VueRouter({
  // mode: 'hhistory',
  base: process.env.BASE_URL,
  routes,
});
export function resetRouter () {
  const newRouter = router()
  router.matcher = newRouter.matcher // the relevant part
}
export default router;
