import Vue from 'vue'
import Router from 'vue-router'
import Home from '@/views/Home.vue'
import Index from '@/views/Index.vue'
// import Mine from 'views/Mine.vue'

import store from '@/store'

Vue.use(Router)

let routes = [{
  path: '/',
  name: 'home',
  component: Home,
  meta: {
    title: '首页',
    keepAlive: true
  }
},
{
  path: '/index',
  name: 'index',
  component: Index,
  // redirect: '/index/todaypatients',
  meta: {
    title: '云诊所',
    keepAlive: true
  },
  children: [{
    path: 'gangplank',
    name: 'gangplank',
    component: () => import('@/views/gangplank.vue'),
    meta: {
      title: '',
      pftitle: ''
    }
  },]

},
{
  path: '/validation',
  name: 'validation',
  component: () => import('../views/Validation.vue')
  },
{
  path: '/hisEnter',
  name: 'hisEnter',
  component: () => import('../views/hisEnter.vue')
},
{
  path: '/404',
  name: '404',
  component: () => import( /* webpackChunkName: "404" */ '@/views/404.vue'),
  meta: {
    title: '404',
    keepAlive: true
  }
}
]

const routerContext = require.context('./', true, /\.js$/)
routerContext.keys().forEach(route => {
  // 如果是根目录的 index.js 、不处理
  if (route.startsWith('./index')) {
    return
  }
  const routerModule = routerContext(route)
  /**
   * 兼容 import export 和 require module.export 两种规范
   */

  routes[1].children = routes[1].children.concat(routerModule.default || routerModule)
  // routes = routes.concat(routerModule.default || routerModule)

})

routes = routes.concat({
  path: '*',
  redirect: '/404'
})

const createRouter = () => new Router({
  // mode: 'history', // require service support
  // base: process.env.BASE_URL,

  routes
})

const myRouter = createRouter()

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




export default myRouter