index.js 5.83 KB
Newer Older
冯超鹏's avatar
冯超鹏 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
import Vue from 'vue';
import Router from 'vue-router';

/**
 * Layzloading will create many files and slow on compiling, so best not to use lazyloading on devlopment.
 * The syntax is lazyloading, but we convert to proper require() with babel-plugin-syntax-dynamic-import
 * @see https://doc.laravue.dev/guide/advanced/lazy-loading.html
 */

Vue.use(Router);

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

/* Router for modules */
冯超鹏's avatar
冯超鹏 committed
16 17 18
// import componentRoutes from './modules/components';
// import chartsRoutes from './modules/charts';
// import tableRoutes from './modules/table';
冯超鹏's avatar
冯超鹏 committed
19
import adminRoutes from './modules/admin';
冯超鹏's avatar
冯超鹏 committed
20
import deviceRoutes from './modules/device';
冯超鹏's avatar
冯超鹏 committed
21
import usersRoutes from './modules/users';
冯超鹏's avatar
冯超鹏 committed
22 23 24
// import nestedRoutes from './modules/nested';
// import errorRoutes from './modules/error';
// import permissionRoutes from './modules/permission';
Administrator's avatar
Administrator committed
25 26
import historyRoutes from './modules/history.js';
import monitorRoutes from './modules/monitor.js';
27
import userdeviceRoutes from './modules/userdevice';
冯超鹏's avatar
冯超鹏 committed
28 29 30 31 32 33 34 35 36 37 38 39 40

/**
 * Sub-menu only appear when children.length>=1
 * @see https://doc.laravue.dev/guide/essentials/router-and-nav.html
 **/

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirect in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
41
* me
冯超鹏's avatar
冯超鹏 committed
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
    roles: ['admin', 'editor']   Visible for these roles only
    permissions: ['view menu zip', 'manage user'] Visible for these permissions only
    title: 'title'               the name show in sub-menu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    noCache: true                if true, the page will no be cached(default is false)
    breadcrumb: false            if false, the item will hidden in breadcrumb (default is true)
    affix: true                  if true, the tag will affix in the tags-view
  }
**/

export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
57 58
    meta: { roles: ['admin'] },
    permissions: ['admin'],
冯超鹏's avatar
冯超鹏 committed
59 60 61 62 63 64 65 66 67 68 69 70
    children: [
      {
        path: '/redirect/:path*',
        component: () => import('@/views/redirect/index'),
      },
    ],
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true,
  },
Administrator's avatar
Administrator committed
71 72 73 74 75
  {
    path: '/userslogin',
    component: () => import('@/views/userslogin/index'),
    hidden: true,
  },
冯超鹏's avatar
冯超鹏 committed
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/AuthRedirect'),
    hidden: true,
  },
  {
    path: '/404',
    redirect: { name: 'Page404' },
    component: () => import('@/views/error-page/404'),
    hidden: true,
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true,
  },
  {
    path: '',
    component: Layout,
    redirect: 'dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
101
        meta: { title: 'dashboard', icon: 'dashboard', noCache: false, permissions: ['view menu dashboard'] },
冯超鹏's avatar
冯超鹏 committed
102 103 104
      },
    ],
  },
冯超鹏's avatar
冯超鹏 committed
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
  // {
  //   path: '/documentation',
  //   component: Layout,
  //   redirect: '/documentation/index',
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/documentation/index'),
  //       name: 'Documentation',
  //       meta: { title: 'documentation', icon: 'documentation', noCache: true },
  //     },
  //   ],
  // },
  // {
  //   path: '/guide',
  //   component: Layout,
  //   redirect: '/guide/index',
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/guide/index'),
  //       name: 'Guide',
  //       meta: { title: 'guide', icon: 'guide', noCache: true },
  //     },
  //   ],
  // },
冯超鹏's avatar
冯超鹏 committed
131 132 133
];

export const asyncRoutes = [
冯超鹏's avatar
冯超鹏 committed
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
  // permissionRoutes,
  // componentRoutes,
  // chartsRoutes,
  // nestedRoutes,
  // tableRoutes,
  // {
  //   path: '/theme',
  //   component: Layout,
  //   redirect: 'noredirect',
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/theme/index'),
  //       name: 'Theme',
  //       meta: { title: 'theme', icon: 'theme' },
  //     },
  //   ],
  // },
152 153 154 155 156 157
  monitorRoutes,
  historyRoutes,
  deviceRoutes,
  usersRoutes,
  adminRoutes,
  userdeviceRoutes,
冯超鹏's avatar
冯超鹏 committed
158
  // {
159
  //   path: '/userdevice',
冯超鹏's avatar
冯超鹏 committed
160 161
  //   component: Layout,
  //   redirect: 'noredirect',
162 163
  //   hidden: false,
  //   meta: { permissions: ['view menu userdevice'], roles: ['user'] },
冯超鹏's avatar
冯超鹏 committed
164 165 166
  //   children: [
  //     {
  //       path: 'index',
167 168 169
  //       component: () => import('@/views/userdevice/index'),
  //       name: 'userdevice',
  //       meta: { title: '设备列表', icon: 'tree-table' },
冯超鹏's avatar
冯超鹏 committed
170 171 172
  //     },
  //   ],
  // },
173 174 175 176 177 178 179 180 181 182 183 184 185 186
  {
    path: '/map',
    component: Layout,
    redirect: '/map',
    children: [
      {
        path: 'map',
        component: () => import('@/views/map/index'),
        name: 'Map',
        meta: { title: 'map', icon: 'international', noCache: false },
      },
    ],
  },
  { path: '/', redirect: '/error/404', hidden: true },
冯超鹏's avatar
冯超鹏 committed
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
];

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  base: process.env.MIX_LARAVUE_PATH,
  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;