index.js 9.9 KB
Newer Older
1 2
import Vue from "vue";
import Router from "vue-router";
lanbaoming's avatar
lanbaoming committed
3

4
Vue.use(Router);
lanbaoming's avatar
lanbaoming committed
5 6

/* Layout */
7
import Layout from "@/layout";
lanbaoming's avatar
lanbaoming committed
8 9

/* Router Modules */
10 11 12 13 14 15
import componentsRouter from "./modules/components";
import chartsRouter from "./modules/charts";
import tableRouter from "./modules/table";
import nestedRouter from "./modules/nested";
import jiedaoRouter from "@/router/modules/jiedao";
import Jdlayout from "@/layout/jdlayout";
lanbaoming's avatar
lanbaoming committed
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
45
    path: "/redirect",
lanbaoming's avatar
lanbaoming committed
46 47 48 49
    component: Layout,
    hidden: true,
    children: [
      {
50 51 52 53
        path: "/redirect/:path(.*)",
        component: () => import("@/views/redirect/index"),
      },
    ],
lanbaoming's avatar
lanbaoming committed
54 55
  },
  {
56 57 58
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true,
lanbaoming's avatar
lanbaoming committed
59 60
  },
  {
61 62 63
    path: "/registered",
    component: () => import("@/views/registered/index"),
    hidden: true,
lanbaoming's avatar
lanbaoming committed
64 65
  },
  {
66 67 68 69 70 71 72 73
    path: "/myInfo",
    component: () => import("@/views/my_info/my_info.vue"),
    hidden: true,
  },
  {
    path: "/reset-password",
    component: () => import("@/views/registered/resetpwd"),
    hidden: true,
lanbaoming's avatar
lanbaoming committed
74 75
  },
  {
76 77 78
    path: "/auth-redirect",
    component: () => import("@/views/login/auth-redirect"),
    hidden: true,
lanbaoming's avatar
lanbaoming committed
79 80
  },
  {
81 82 83 84
    path: "/jd-transport",
    component: () => import("@/views/jiedao/profile/transport"),
    name: "Logistics",
    meta: { title: "logistics" },
lanbaoming's avatar
lanbaoming committed
85 86
  },
  {
87 88 89 90
    path: "/jd-erate",
    component: () => import("@/views/jiedao/profile/erate"),
    name: "Ecash",
    meta: { title: "ecash" },
lanbaoming's avatar
lanbaoming committed
91 92
  },
  {
93 94 95
    path: "/404",
    component: () => import("@/views/error-page/404"),
    hidden: true,
lanbaoming's avatar
lanbaoming committed
96 97
  },
  {
98 99 100
    path: "/401",
    component: () => import("@/views/error-page/401"),
    hidden: true,
lanbaoming's avatar
lanbaoming committed
101 102
  },
  {
103
    path: "/",
lanbaoming's avatar
lanbaoming committed
104
    component: Jdlayout,
105
    redirect: "/jiedao",
lanbaoming's avatar
lanbaoming committed
106 107
    children: [
      {
108 109 110 111 112 113 114 115
        path: "dashboard",
        component: () => import("@/views/jiedao/profile"),
        name: "Dashboard",
        meta: { title: "dashboard", icon: "dashboard", affix: true },
      },
    ],
  },
];
lanbaoming's avatar
lanbaoming committed
116 117 118 119 120 121 122

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [
  {
123
    path: "/permission",
lanbaoming's avatar
lanbaoming committed
124
    component: Layout,
125
    redirect: "/permission/page",
lanbaoming's avatar
lanbaoming committed
126
    alwaysShow: true, // will always show the root menu
127
    name: "Permission",
lanbaoming's avatar
lanbaoming committed
128
    meta: {
129 130 131
      title: "permission",
      icon: "lock",
      roles: ["admin", "editor"], // you can set roles in root nav
lanbaoming's avatar
lanbaoming committed
132 133 134
    },
    children: [
      {
135 136 137
        path: "page",
        component: () => import("@/views/permission/page"),
        name: "PagePermission",
lanbaoming's avatar
lanbaoming committed
138
        meta: {
139 140 141
          title: "pagePermission",
          roles: ["admin"], // or you can only set roles in sub nav
        },
lanbaoming's avatar
lanbaoming committed
142 143
      },
      {
144 145 146
        path: "directive",
        component: () => import("@/views/permission/directive"),
        name: "DirectivePermission",
lanbaoming's avatar
lanbaoming committed
147
        meta: {
148
          title: "directivePermission",
lanbaoming's avatar
lanbaoming committed
149
          // if do not set roles, means: this page does not require permission
150
        },
lanbaoming's avatar
lanbaoming committed
151 152
      },
      {
153 154 155
        path: "role",
        component: () => import("@/views/permission/role"),
        name: "RolePermission",
lanbaoming's avatar
lanbaoming committed
156
        meta: {
157 158 159 160 161
          title: "rolePermission",
          roles: ["admin"],
        },
      },
    ],
lanbaoming's avatar
lanbaoming committed
162 163 164
  },

  {
165
    path: "/icon",
lanbaoming's avatar
lanbaoming committed
166 167 168
    component: Layout,
    children: [
      {
169 170 171 172 173 174
        path: "index",
        component: () => import("@/views/icons/index"),
        name: "Icons",
        meta: { title: "icons", icon: "icon", noCache: true },
      },
    ],
lanbaoming's avatar
lanbaoming committed
175 176 177 178 179 180 181 182 183 184
  },

  /** when your routing map is too long, you can split it into small modules **/
  componentsRouter,
  chartsRouter,
  nestedRouter,
  tableRouter,
  jiedaoRouter,

  {
185
    path: "/example",
lanbaoming's avatar
lanbaoming committed
186
    component: Layout,
187 188
    redirect: "/example/list",
    name: "Example",
lanbaoming's avatar
lanbaoming committed
189
    meta: {
190 191
      title: "example",
      icon: "el-icon-s-help",
lanbaoming's avatar
lanbaoming committed
192 193 194
    },
    children: [
      {
195 196 197 198
        path: "create",
        component: () => import("@/views/example/create"),
        name: "CreateArticle",
        meta: { title: "createArticle", icon: "edit" },
lanbaoming's avatar
lanbaoming committed
199 200
      },
      {
201 202 203 204 205 206 207 208 209
        path: "edit/:id(\\d+)",
        component: () => import("@/views/example/edit"),
        name: "EditArticle",
        meta: {
          title: "editArticle",
          noCache: true,
          activeMenu: "/example/list",
        },
        hidden: true,
lanbaoming's avatar
lanbaoming committed
210 211
      },
      {
212 213 214 215 216 217
        path: "list",
        component: () => import("@/views/example/list"),
        name: "ArticleList",
        meta: { title: "articleList", icon: "list" },
      },
    ],
lanbaoming's avatar
lanbaoming committed
218 219 220
  },

  {
221
    path: "/tab",
lanbaoming's avatar
lanbaoming committed
222 223 224
    component: Layout,
    children: [
      {
225 226 227 228 229 230
        path: "index",
        component: () => import("@/views/tab/index"),
        name: "Tab",
        meta: { title: "tab", icon: "tab" },
      },
    ],
lanbaoming's avatar
lanbaoming committed
231 232 233
  },

  {
234
    path: "/error",
lanbaoming's avatar
lanbaoming committed
235
    component: Layout,
236 237
    redirect: "noRedirect",
    name: "ErrorPages",
lanbaoming's avatar
lanbaoming committed
238
    meta: {
239 240
      title: "errorPages",
      icon: "404",
lanbaoming's avatar
lanbaoming committed
241 242 243
    },
    children: [
      {
244 245 246 247
        path: "401",
        component: () => import("@/views/error-page/401"),
        name: "Page401",
        meta: { title: "page401", noCache: true },
lanbaoming's avatar
lanbaoming committed
248 249
      },
      {
250 251 252 253 254 255
        path: "404",
        component: () => import("@/views/error-page/404"),
        name: "Page404",
        meta: { title: "page404", noCache: true },
      },
    ],
lanbaoming's avatar
lanbaoming committed
256 257 258
  },

  {
259
    path: "/error-log",
lanbaoming's avatar
lanbaoming committed
260 261 262
    component: Layout,
    children: [
      {
263 264 265 266 267 268
        path: "log",
        component: () => import("@/views/error-log/index"),
        name: "ErrorLog",
        meta: { title: "errorLog", icon: "bug" },
      },
    ],
lanbaoming's avatar
lanbaoming committed
269 270 271
  },

  {
272
    path: "/excel",
lanbaoming's avatar
lanbaoming committed
273
    component: Layout,
274 275
    redirect: "/excel/export-excel",
    name: "Excel",
lanbaoming's avatar
lanbaoming committed
276
    meta: {
277 278
      title: "excel",
      icon: "excel",
lanbaoming's avatar
lanbaoming committed
279 280 281
    },
    children: [
      {
282 283 284 285
        path: "export-excel",
        component: () => import("@/views/excel/export-excel"),
        name: "ExportExcel",
        meta: { title: "exportExcel" },
lanbaoming's avatar
lanbaoming committed
286 287
      },
      {
288 289 290 291
        path: "export-selected-excel",
        component: () => import("@/views/excel/select-excel"),
        name: "SelectExcel",
        meta: { title: "selectExcel" },
lanbaoming's avatar
lanbaoming committed
292 293
      },
      {
294 295 296 297
        path: "export-merge-header",
        component: () => import("@/views/excel/merge-header"),
        name: "MergeHeader",
        meta: { title: "mergeHeader" },
lanbaoming's avatar
lanbaoming committed
298 299
      },
      {
300 301 302 303 304 305
        path: "upload-excel",
        component: () => import("@/views/excel/upload-excel"),
        name: "UploadExcel",
        meta: { title: "uploadExcel" },
      },
    ],
lanbaoming's avatar
lanbaoming committed
306 307 308
  },

  {
309
    path: "/zip",
lanbaoming's avatar
lanbaoming committed
310
    component: Layout,
311
    redirect: "/zip/download",
lanbaoming's avatar
lanbaoming committed
312
    alwaysShow: true,
313 314
    name: "Zip",
    meta: { title: "zip", icon: "zip" },
lanbaoming's avatar
lanbaoming committed
315 316
    children: [
      {
317 318 319 320 321 322
        path: "download",
        component: () => import("@/views/zip/index"),
        name: "ExportZip",
        meta: { title: "exportZip" },
      },
    ],
lanbaoming's avatar
lanbaoming committed
323 324 325
  },

  {
326
    path: "/pdf",
lanbaoming's avatar
lanbaoming committed
327
    component: Layout,
328
    redirect: "/pdf/index",
lanbaoming's avatar
lanbaoming committed
329 330
    children: [
      {
331 332 333 334 335 336
        path: "index",
        component: () => import("@/views/pdf/index"),
        name: "PDF",
        meta: { title: "pdf", icon: "pdf" },
      },
    ],
lanbaoming's avatar
lanbaoming committed
337 338
  },
  {
339 340 341
    path: "/pdf/download",
    component: () => import("@/views/pdf/download"),
    hidden: true,
lanbaoming's avatar
lanbaoming committed
342 343 344
  },

  {
345
    path: "/theme",
lanbaoming's avatar
lanbaoming committed
346 347 348
    component: Layout,
    children: [
      {
349 350 351 352 353 354
        path: "index",
        component: () => import("@/views/theme/index"),
        name: "Theme",
        meta: { title: "theme", icon: "theme" },
      },
    ],
lanbaoming's avatar
lanbaoming committed
355 356 357
  },

  {
358
    path: "/clipboard",
lanbaoming's avatar
lanbaoming committed
359 360 361
    component: Layout,
    children: [
      {
362 363 364 365 366 367
        path: "index",
        component: () => import("@/views/clipboard/index"),
        name: "ClipboardDemo",
        meta: { title: "clipboardDemo", icon: "clipboard" },
      },
    ],
lanbaoming's avatar
lanbaoming committed
368 369 370
  },

  {
371
    path: "/i18n",
lanbaoming's avatar
lanbaoming committed
372 373 374
    component: Layout,
    children: [
      {
375 376 377 378 379 380
        path: "index",
        component: () => import("@/views/i18n-demo/index"),
        name: "I18n",
        meta: { title: "i18n", icon: "international" },
      },
    ],
lanbaoming's avatar
lanbaoming committed
381 382 383
  },

  {
384
    path: "external-link",
lanbaoming's avatar
lanbaoming committed
385 386 387
    component: Layout,
    children: [
      {
388 389 390 391
        path: "https://github.com/PanJiaChen/vue-element-admin",
        meta: { title: "externalLink", icon: "link" },
      },
    ],
lanbaoming's avatar
lanbaoming committed
392 393 394
  },

  // 404 page must be placed at the end !!!
395 396
  { path: "*", redirect: "/404", hidden: true },
];
lanbaoming's avatar
lanbaoming committed
397

398 399 400 401 402 403
const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes,
  });
lanbaoming's avatar
lanbaoming committed
404

405
const router = createRouter();
lanbaoming's avatar
lanbaoming committed
406 407 408

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
409 410
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
lanbaoming's avatar
lanbaoming committed
411 412
}

413
export default router;