import Vue from 'vue'
import Router from 'vue-router'
import path from '@/router/RoutingPath'
const Layout = () => import("@/layout/index.vue")

Vue.use(Router)

const routerPush = Router.prototype.push
Router.prototype.push = function push(location,onResolve,onReject) {
  if (onResolve || onReject){
    return routerPush.call(this, location, onResolve, onReject)
  }
  return routerPush.call(this, location).catch(error => error)
}

export const constantRouterMap = [
  {
    path: '',
    redirect: "home",
    hidden: true
  },
  {
    path: '/login',
    name: 'login',
    component: path.logins,
    meta: {
      title: '登录',
    },
    hidden: true,
  },
  // {path: '/404', component: path.page404, name: 'page404'},　
  {
    name: "error",
    path: "/error",
    hidden: true,
    redirect: "404",
    component: Layout,
    // alwaysShow: true,
    // meta: { title: "报错", icon: "system", noCache: false },
    children: [
      {
        name: "page404",
        path: "/404",
        hidden: false,
        component: path.page404,
        meta: { title: "404", icon: "user", noCache: false },
      }
    ],
  },
  {
    name: "home",
    path: "/home",
    component: Layout,
    hidden: false,
    redirect: "home",
    alwaysShow: false,
    meta: { title: "工作台", icon: "table", noCache: false },
    children: [
      {
        name: "home",
        path: "/home",
        hidden: false,
        component: path.home,
        meta: { title: "工作台", icon: "el-icon-menu", noCache: false },
      }
    ],
  },
]


const router = new Router({
  mode: 'history', // 去掉url中的#
  routes: constantRouterMap
})

export default router