import Vue from 'vue'
import Router from 'vue-router'

/**
 * vue-router报错Uncaught (in promise)及解决方法
 * 对Router原型链上的push方法进行重写，这样就不用每次调用方法都要加上catch
 */
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)
}

Vue.use(Router)

export const constantRoutes = [
  {
    path: '/',
    name: 'web',
    redirect: '/',
    component: () => import('@/views/front/layout'),
    children: [
      {
        path: '/',
        name: 'Home',
        component: () => import('@/views/front/home'),
        meta: {
          title: 'home'
        }
      },
      {
        path: '/home',
        name: 'Home',
        component: () => import('@/views/front/home'),
        meta: {
          title: 'home'
        }
      },
      {
        path: '/about',
        name: 'About',
        component: () => import('@/views/front/about'),
        meta: {
          title: 'about'
        }
      },
      {
        path: '/services',
        name: 'Services',
        component: () => import('@/views/front/services'),
        meta: {
          title: 'services'
        }
      },
      {
        path: '/services',
        redirect: '/services',
        component: () => import('@/views/front/services/layout'),
        children: [
          {
            path: '/services/centralizedImagingServices',
            name: 'Center Imaging Services',
            component: () => import('@/views/front/services/centralized-imaging-services')
          },
          {
            path: '/services/3DPostProcessingServices',
            name: '3D Post Processing Services',
            component: () => import('@/views/front/services/3D-post-processing-services'),
          },
          {
            path: '/services/ImageBasedSurgicalPlanning',
            name: 'Image Based Surgical Planning',
            component: () => import('@/views/front/services/3D-post-processing-services/Image-Based-Surgical-Planning')
          },
        ]
      },
      {
        path: '/book',
        name: 'Book',
        component: () => import('@/views/front/book'),
        meta: {
          title: 'book'
        }
      },
      {
        path: '/media',
        name: 'Media',
        component: () => import('@/views/front/media'),
        meta: {
          title: 'media'
        }
      }
    ]
  }
]

export default new Router({
  base: '/',
  mode: 'history', // 去掉url中的#
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})
