import Vue from 'vue';
import VueRouter from 'vue-router';

Vue.use(VueRouter);

//replace报错
const originalReplace = VueRouter.prototype.replace;
VueRouter.prototype.replace = function replace(location) {
  return originalReplace.call(this, location).catch(err => err);
};
//push报错
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err);
};

const routes = [
  {
    path: '/',
    redirect: '/login',
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/login'),
    meta: {
      title: "登录页",
      needToken: false
    }
  },
  {
    path: '/register',
    name: 'register',
    component: () => import('@/register'),
    meta: {
      title: "注册页",
      needToken: false
    }
  },
  {
    path: '/home',
    redirect: "/home/index",
    name: 'Home',
    component: () => import(/* webpackChunkName: "Home" */"@/home"),
    meta: {
      title: "首页",
      needToken: true
    },
    children: [
      {
        path: '/home/index',
        name: 'HomeIndex',
        component: () => import(/* webpackChunkName: "Home" */"@/views/certificationManagement"),
        meta: {
          title: "认证管理",
          needToken: true,
          show: true
        },
      }
    ]
  },
];

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
});

export default router;

export { routes };
