Skip to content
index.js 9.42 KiB
Newer Older
wangqinghua's avatar
wangqinghua committed
import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)
wangqinghua's avatar
wangqinghua committed

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

/* Router Modules */
import componentsRouter from './modules/components'
wangqinghua's avatar
wangqinghua committed
// import chartsRouter from './modules/charts'
wangqinghua's avatar
wangqinghua committed
import tableRouter from './modules/table'
import nestedRouter from './modules/nested'

export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path*',
wangqinghua's avatar
wangqinghua committed
        component: () => import('@/views/redirect/index')
wangqinghua's avatar
wangqinghua committed
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
wangqinghua's avatar
wangqinghua committed
    component: () => import('@/views/login/auth-redirect'),
wangqinghua's avatar
wangqinghua committed
    hidden: true
  },
  {
    path: '/404',
wangqinghua's avatar
wangqinghua committed
    component: () => import('@/views/error-page/404'),
wangqinghua's avatar
wangqinghua committed
    hidden: true
  },
  {
    path: '/401',
    // component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
wangqinghua's avatar
wangqinghua committed
        component: () => import('@/views/dashboard/index'),
wangqinghua's avatar
wangqinghua committed
        name: 'Dashboard',
wangqinghua's avatar
wangqinghua committed
        meta: { title: '首页', icon: 'dashboard', affix: true }
wangqinghua's avatar
wangqinghua committed
      }
    ]
  },
  {
    path: '/guide',
    component: Layout,
    redirect: '/guide/index',
    children: [
      {
wangqinghua's avatar
wangqinghua committed
        path: 'index',
wangqinghua's avatar
wangqinghua committed
        component: () => import('@/views/guide/index'),
wangqinghua's avatar
wangqinghua committed
        name: 'Guide',
wangqinghua's avatar
wangqinghua committed
        meta: { title: '引导页', icon: 'guide', noCache: true }
wangqinghua's avatar
wangqinghua committed
      }
    ]
  },
  {
    path: '/profile',
    component: Layout,
    redirect: '/profile/index',
    hidden: true,
    children: [
      {
wangqinghua's avatar
wangqinghua committed
        path: 'index',
wangqinghua's avatar
wangqinghua committed
        component: () => import('@/views/profile/index'),
wangqinghua's avatar
wangqinghua committed
        name: 'Profile',
        meta: { title: 'profile', icon: 'user', noCache: true }
      }
    ]
  }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
wangqinghua's avatar
wangqinghua committed
  // {
  //   path: '/permission',
  //   component: Layout,
  //   redirect: '/permission/page',
  //   alwaysShow: true, // will always show the root menu
  //   name: 'Permission',
  //   meta: {
  //     title: 'permission',
  //     icon: 'lock',
  //     roles: ['admin', 'editor'] // you can set roles in root nav
  //   },
  //   children: [
  //     {
  //       path: 'page',
  //       component: () => import('@/views/permission/page'),
  //       name: 'PagePermission',
  //       meta: {
  //         title: 'pagePermission',
  //         roles: ['admin'] // or you can only set roles in sub nav
  //       }
  //     },
  //     {
  //       path: 'directive',
  //       component: () => import('@/views/permission/directive'),
  //       name: 'DirectivePermission',
  //       meta: {
  //         title: 'directivePermission'
  //         // if do not set roles, means: this page does not require permission
  //       }
  //     },
  //     {
  //       path: 'role',
  //       component: () => import('@/views/permission/role'),
  //       name: 'RolePermission',
  //       meta: {
  //         title: 'rolePermission',
  //         roles: ['admin']
  //       }
  //     }
  //   ]
  // },
wangqinghua's avatar
wangqinghua committed

  {
    path: '/icon',
    component: Layout,
    children: [
      {
wangqinghua's avatar
wangqinghua committed
        path: 'index',
wangqinghua's avatar
wangqinghua committed
        component: () => import('@/views/icons/index'),
wangqinghua's avatar
wangqinghua committed
        name: 'Icons',
wangqinghua's avatar
wangqinghua committed
        meta: { title: '图标', icon: 'icon', noCache: true }
wangqinghua's avatar
wangqinghua committed
      }
    ]
  },

  /** when your routing map is too long, you can split it into small modules **/
  componentsRouter,
wangqinghua's avatar
wangqinghua committed
  // chartsRouter,
wangqinghua's avatar
wangqinghua committed
  nestedRouter,
  tableRouter,

  // {
  //   path: '/example',
  //   component: Layout,
  //   redirect: '/example/list',
  //   name: 'Example',
  //   meta: {
  //     title: 'example',
  //     icon: 'example'
  //   },
  //   children: [
  //     {
  //       path: 'create',
  //       component: () => import('@/views/example/create'),
  //       name: 'CreateArticle',
  //       meta: { title: 'createArticle', icon: 'edit' }
  //     },
  //     {
  //       path: 'edit/:id(\\d+)',
  //       component: () => import('@/views/example/edit'),
  //       name: 'EditArticle',
  //       meta: { title: 'editArticle', noCache: true, activeMenu: '/example/list' },
  //       hidden: true
  //     },
  //     {
  //       path: 'list',
  //       component: () => import('@/views/example/list'),
  //       name: 'ArticleList',
  //       meta: { title: 'articleList', icon: 'list' }
  //     }
  //   ]
  // },

  {
    path: '/tab',
    component: Layout,
    children: [
      {
wangqinghua's avatar
wangqinghua committed
        path: 'index',
wangqinghua's avatar
wangqinghua committed
        component: () => import('@/views/tab/index'),
wangqinghua's avatar
wangqinghua committed
        name: 'Tab',
        meta: { title: 'tab', icon: 'tab' }
      }
    ]
  },

  {
    path: '/error',
    component: Layout,
    redirect: 'noRedirect',
    name: 'ErrorPages',
    meta: {
      title: 'errorPages',
      icon: '404'
    },
    children: [
      {
        path: '401',
wangqinghua's avatar
wangqinghua committed
        component: () => import('@/views/error-page/401'),
wangqinghua's avatar
wangqinghua committed
        name: 'Page401',
wangqinghua's avatar
wangqinghua committed
        meta: { title: '401', noCache: true }
wangqinghua's avatar
wangqinghua committed
      },
      {
        path: '404',
wangqinghua's avatar
wangqinghua committed
        component: () => import('@/views/error-page/404'),
wangqinghua's avatar
wangqinghua committed
        name: 'Page404',
wangqinghua's avatar
wangqinghua committed
        meta: { title: '404', noCache: true }
wangqinghua's avatar
wangqinghua committed
      }
    ]
  },

wangqinghua's avatar
wangqinghua committed
  // {
  //   path: '/error-log',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'log',
  //       component: () => import('@/views/error-log/index'),
  //       name: 'ErrorLog',
  //       meta: { title: 'errorLog', icon: 'bug' }
  //     }
  //   ]
  // },

  // {
  //   path: '/excel',
  //   component: Layout,
  //   redirect: '/excel/export-excel',
  //   name: 'Excel',
  //   meta: {
  //     title: 'excel',
  //     icon: 'excel'
  //   },
  //   children: [
  //     {
  //       path: 'export-excel',
  //       component: () => import('@/views/excel/export-excel'),
  //       name: 'ExportExcel',
  //       meta: {title: 'exportExcel'}
  //     },
  //     {
  //       path: 'export-selected-excel',
  //       component: () => import('@/views/excel/select-excel'),
  //       name: 'SelectExcel',
  //       meta: {title: 'selectExcel'}
  //     },
  //     {
  //       path: 'export-merge-header',
  //       component: () => import('@/views/excel/merge-header'),
  //       name: 'MergeHeader',
  //       meta: {title: 'mergeHeader'}
  //     },
  //     {
  //       path: 'upload-excel',
  //       component: () => import('@/views/excel/upload-excel'),
  //       name: 'UploadExcel',
  //       meta: {title: 'uploadExcel'}
  //     }
  //   ]
  // },

  // {
  //   path: '/zip',
  //   component: Layout,
  //   redirect: '/zip/download',
  //   alwaysShow: true,
  //   name: 'Zip',
  //   meta: { title: 'zip', icon: 'zip' },
  //   children: [
  //     {
  //       path: 'download',
  //       component: () => import('@/views/zip/index'),
  //       name: 'ExportZip',
  //       meta: { title: 'exportZip' }
  //     }
  //   ]
  // },

  // {
  //   path: '/pdf',
  //   component: Layout,
  //   redirect: '/pdf/index',
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/pdf/index'),
  //       name: 'PDF',
  //       meta: { title: 'pdf', icon: 'pdf' }
  //     }
  //   ]
  // },
  // {
  //   path: '/pdf/download',
  //   component: () => import('@/views/pdf/download'),
  //   hidden: true
  // },
wangqinghua's avatar
wangqinghua committed

  {
wangqinghua's avatar
wangqinghua committed
    path: '/file',
wangqinghua's avatar
wangqinghua committed
    component: Layout,
wangqinghua's avatar
wangqinghua committed
    name: 'file',
wangqinghua's avatar
wangqinghua committed
    meta: {
wangqinghua's avatar
wangqinghua committed
      title: '文件',
      icon: 'list'
wangqinghua's avatar
wangqinghua committed
    },
    children: [
      {
wangqinghua's avatar
wangqinghua committed
        path: '/pdf-view',
        component: () => import('@/views/file/pdf-view'),
        name: 'pdf-view',
        meta: { title: 'PDF预览' }
wangqinghua's avatar
wangqinghua committed
      },
      {
wangqinghua's avatar
wangqinghua committed
        path: '/file-upload',
        component: () => import('@/views/file/file-upload'),
        name: 'file-upload',
        meta: { title: '文件上传' }
wangqinghua's avatar
wangqinghua committed
      },
      {
wangqinghua's avatar
wangqinghua committed
        path: '/file-download',
        component: () => import('@/views/file/file-download'),
        name: 'file-download',
        meta: { title: '文件下载' }
wangqinghua's avatar
wangqinghua committed
      }
    ]
  },

  {
    path: '/theme',
    component: Layout,
    children: [
      {
wangqinghua's avatar
wangqinghua committed
        path: 'index',
wangqinghua's avatar
wangqinghua committed
        component: () => import('@/views/theme/index'),
wangqinghua's avatar
wangqinghua committed
        name: 'Theme',
wangqinghua's avatar
wangqinghua committed
        meta: { title: '换肤', icon: 'theme' }
wangqinghua's avatar
wangqinghua committed
      }
    ]
  },

wangqinghua's avatar
wangqinghua committed
  // {
  //   path: '/clipboard',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/clipboard/index'),
  //       name: 'ClipboardDemo',
  //       meta: { title: 'clipboardDemo', icon: 'clipboard' }
  //     }
  //   ]
  // },
wangqinghua's avatar
wangqinghua committed

wangqinghua's avatar
wangqinghua committed
  // {
  //   path: '/i18n',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/i18n-demo/index'),
  //       name: 'I18n',
  //       meta: { title: 'i18n', icon: 'international' }
  //     }
  //   ]
  // },

  // {
  //   path: 'external-link',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'https://github.com/PanJiaChen/vue-element-admin',
  //       meta: { title: 'externalLink', icon: 'link' }
  //     }
  //   ]
  // },
wangqinghua's avatar
wangqinghua committed

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

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

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router