index.js 1.88 KB
Newer Older
Pan's avatar
Pan committed
1 2 3
import Vue from 'vue';
import Router from 'vue-router';
const _import = require('./_import_' + process.env.NODE_ENV);
Pan's avatar
Pan committed
4
// in development env not use Lazy Loading,because Lazy Loading large page will cause webpack hot update too slow.so only in production use Lazy Loading
Pan's avatar
Pan committed
5 6 7 8 9 10 11 12 13 14 15 16 17

/* layout */
import Layout from '../views/layout/Layout';

/* login */
const Login = _import('login/index');

/* dashboard */
const dashboard = _import('dashboard/index');

/* error page */
const Err404 = _import('404');

Pan's avatar
Pan committed
18
/* demo page */
Pan's avatar
Pan committed
19 20
const Form = _import('page/form');
const Table = _import('table/index');
Pan's avatar
Pan committed
21 22 23 24 25

Vue.use(Router);

 /**
  * icon : the icon show in the sidebar
Pan's avatar
Pan committed
26 27 28 29
  * hidden : if `hidden:true` will not show in the sidebar
  * redirect : if `redirect:noredirect` will not redirct in the levelbar
  * noDropdown : if `noDropdown:true` will not has submenu in the sidebar
  * meta : `{ role: ['admin'] }`  will control the page role
Pan's avatar
Pan committed
30 31
  **/
export const constantRouterMap = [
Pan's avatar
Pan committed
32
  { path: '/login', component: Login, hidden: true },
Pan's avatar
Pan committed
33 34 35 36 37
  { path: '/404', component: Err404, hidden: true },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
Pan's avatar
Pan committed
38
    name: 'Home',
Pan's avatar
Pan committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
    hidden: true,
    children: [{ path: 'dashboard', component: dashboard }]
  }
]

export default new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
});

export const asyncRouterMap = [
  {
    path: '/example',
    component: Layout,
    redirect: 'noredirect',
Pan's avatar
Pan committed
55 56
    name: 'Example',
    icon: 'zujian',
Pan's avatar
Pan committed
57
    children: [
Pan's avatar
Pan committed
58
      { path: 'index', component: Form, name: 'Form', icon: 'zonghe' }
Pan's avatar
Pan committed
59 60
    ]
  },
Pan's avatar
Pan committed
61

Pan's avatar
Pan committed
62 63 64 65 66 67 68 69 70
  {
    path: '/table',
    component: Layout,
    redirect: '/table/index',
    name: 'Table',
    icon: 'tubiaoleixingzhengchang',
    noDropdown: true,
    children: [{ path: 'index', component: Table, name: 'Table', meta: { role: ['admin'] } }]
  },
Pan's avatar
Pan committed
71

Pan's avatar
Pan committed
72 73
  { path: '*', redirect: '/404', hidden: true }
];