index.js 5.33 KB
import Vue from 'vue'
import Router from 'vue-router'
// import HelloWorld from '@/components/HelloWorld'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'


/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can accessed
 */
export const constantRoutes = [
  {
    path: 'redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/',
    component: Layout,
    hidden: true,
    redirect: 'index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/client/index'),
        name: 'client',
        meta: { title: 'client', icon: 'guide', noCache: true, affix: true, activeMenu: '/index' }
      }
    ]
  },
  {
    path: '/index',
    component: Layout,
    children: [
      {
        path: '',
        component: () => import('@/views/client/index'),
        name: 'client',
        meta: { title: 'client', icon: 'guide', noCache: true, activeMenu: '/index' }
      }
    ]
  },
  {
    path: '/user',
    component: Layout,
    children: [
      {
        path: 'index',
        component: () => import('@/views/user/index'),
        name: 'user',
        meta: { title: 'user', icon: 'user', noCache: true }
      }
    ]
  },
  {
    path: '/resource-type',
    component: Layout,
    children: [
      {
        path: 'index',
        component: () => import('@/views/resource-type/index'),
        name: 'resourceType',
        meta: { title: 'resourceType', icon: 'list', noCache: true }
      }
    ]
  },
  {
    path: '/resource',
    component: Layout,
    children: [
      {
        path: 'index',
        component: () => import('@/views/resource/index'),
        name: 'resource',
        meta: { title: 'resource', icon: 'lock', noCache: true }
      }
    ]
  },
  {
    path: '/message-type',
    component: Layout,
    children: [
      {
        path: 'index',
        component: () => import('@/views/message-type/index'),
        name: 'messageType',
        meta: { title: 'messageType', icon: 'message', noCache: true }
      }
    ]
  },
  {
    path: '/template',
    component: Layout,
    children: [
      {
        path: 'index',
        component: () => import('@/views/template/index'),
        name: 'template',
        meta: { title: 'template', icon: 'nested', noCache: true }
      }
    ]
  },
  // {
  //   path: '/login',
  //   component: () => import('@/views/login/index'),
  //   hidden: true
  // },
  // {
  //   path: '/auth-redirect',
  //   component: () => import('@/views/login/auth-redirect'),
  //   hidden: true
  // },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  { path: '*', redirect: '/404', hidden: true }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  // {
  //   path: '/index',
  //   component: Layout,
  //   children: [
  //     {
  //       path: '',
  //       component: () => import('@/views/client/index'),
  //       name: 'client',
  //       meta: { title: 'client', icon: 'guide', noCache: true, activeMenu: '/index' }
  //     }
  //   ]
  // },
  // {
  //   path: '/user',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/user/index'),
  //       name: 'user',
  //       meta: { title: 'user', icon: 'user', noCache: true }
  //     }
  //   ]
  // },
  // {
  //   path: '/resource-type',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/resource-type/index'),
  //       name: 'resourceType',
  //       meta: { title: 'resourceType', icon: 'list', noCache: true }
  //     }
  //   ]
  // },
  // {
  //   path: '/resource',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/resource/index'),
  //       name: 'resource',
  //       meta: { title: 'resource', icon: 'lock', noCache: true }
  //     }
  //   ]
  // },
  // {
  //   path: '/message-type',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/message-type/index'),
  //       name: 'messageType',
  //       meta: { title: 'messageType', icon: 'message', noCache: true }
  //     }
  //   ]
  // },
  // {
  //   path: '/template',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/template/index'),
  //       name: 'template',
  //       meta: { title: 'template', icon: 'nested', noCache: true }
  //     }
  //   ]
  // },
  // { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history',  // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter () {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher  // reset router
}

export default router


// export default new Router({
//   routes: [
//     {
//       path: '/',
//       name: 'layout',
//       component: Layout
//     }
//   ]
// })