text: import Vue from 'vue';
  import Router from 'vue-router';
  
  Vue.use(Router);
  
  /* 布局组件 */
  import Layout from '@/layout';
  
  /**
   * 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                   当设置 true 的时候该路由不会再侧边栏出现 如401，login等页面，或者如一些编辑页面/edit/1
   * alwaysShow: true               当你一个路由下面的 children 声明的路由大于1个时，自动会变成嵌套的模式--如组件页面
   *                                只有一个时，会将那个子路由当做根路由显示在侧边栏--如引导页面
   *                                若你想不管路由下面的 children 声明的个数都显示你的根路由
   *                                你可以设置 alwaysShow: true，这样它就会忽略之前定义的规则，一直显示根路由
   * redirect: noRedirect           当设置 noredirect 的时候该路由在面包屑导航中不可被点击
   * name:'router-name'            设定路由的名字，一定要填写不然使用<keep-alive>时会出现各种问题
   * meta : {
      roles: ['admin','editor']    设置该路由进入的权限，支持多个权限叠加
      title: 'title'               设置该路由在侧边栏和面包屑中展示的名字
      icon: 'svg-name'             设置该路由的图标
      noCache: false               如果设置为true，页面将不会被缓存(默认为false，添加路由缓存)
      affix: true                  如果设置为true，则标记将附加在标记视图中
      breadcrumb: false            如果设置为false，则不会在breadcrumb面包屑中显示
      activeMenu: '/example/list'  如果设置路径，侧栏将突出显示您设置的路径
    }
   */
  
  /**
   * @description 路由序列
   * @path 路由路径
   * @component 渲染组件
   * */
  export const constantRoutes = [
    {
      path: '/login',
      component: () => import('@/views/login/index'),
      hidden: true
    },
  
    {
      path: '/404',
      component: () => import('@/views/404'),
      hidden: true
    },
  
    {
      path: '/',
      component: Layout,
      redirect: '/HomePage',
      children: [{
        path: 'HomePage',
        name: '首页',
        component: () => import('@/views/dashboard/index'),
        meta: { title: '首页', icon: 'dashboard', affix: true }
      }]
    },
    {
      path: '/jcjMap',
      component: Layout,
      name: '接处警一体化',
      meta: { title: '接处警一体化', icon: 'example' },
      redirect: '/jcjMap/creat',
      children: [
        {
          path: 'creat',
          name: '创建警情',
          component: () => import('@/views/jcjMap/creat'),
          meta: { title: '创建警情', icon: 'dashboard' }
        },
        {
          path: 'edit/:id(\\d+)',
          name: '编辑警情',
          hidden: true,
          component: () => import('@/views/jcjMap/edit'),
          meta: { title: '接处一体化', icon: 'dashboard' }
        }]
    },
    {
      path: '/example',
      component: Layout,
      redirect: '/example/table',
      name: 'Example',
      meta: { title: 'Example', icon: 'example' },
      children: [
        {
          path: 'table',
          name: 'Table',
          component: () => import('@/views/table/index'),
          meta: { title: 'Table', icon: 'table' }
        },
        {
          path: 'tree',
          name: 'Tree',
          component: () => import('@/views/tree/index'),
          meta: { title: 'Tree', icon: 'tree' }
        }
      ]
    },
  
    {
      path: '/form',
      component: Layout,
      children: [
        {
          path: 'index',
          name: 'Form',
          component: () => import('@/views/form/index'),
          meta: { title: 'Form', icon: 'form' }
        }
      ]
    },
  
    {
      path: '/nested',
      component: Layout,
      redirect: '/nested/menu1',
      name: 'Nested',
      meta: {
        title: 'Nested',
        icon: 'nested'
      },
      children: [
        {
          path: 'menu1',
          component: () => import('@/views/nested/menu1/index'), // Parent router-view
          name: 'Menu1',
          meta: { title: 'Menu1' },
          children: [
            {
              path: 'menu1-1',
              component: () => import('@/views/nested/menu1/menu1-1'),
              name: 'Menu1-1',
              meta: { title: 'Menu1-1' }
            },
            {
              path: 'menu1-2',
              component: () => import('@/views/nested/menu1/menu1-2'),
              name: 'Menu1-2',
              meta: { title: 'Menu1-2' },
              children: [
                {
                  path: 'menu1-2-1',
                  component: () => import('@/views/nested/menu1/menu1-2/menu1-2-1'),
                  name: 'Menu1-2-1',
                  meta: { title: 'Menu1-2-1' }
                },
                {
                  path: 'menu1-2-2',
                  component: () => import('@/views/nested/menu1/menu1-2/menu1-2-2'),
                  name: 'Menu1-2-2',
                  meta: { title: 'Menu1-2-2' }
                }
              ]
            },
            {
              path: 'menu1-3',
              component: () => import('@/views/nested/menu1/menu1-3'),
              name: 'Menu1-3',
              meta: { title: 'Menu1-3' }
            }
          ]
        },
        {
          path: 'menu2',
          component: () => import('@/views/nested/menu2/index'),
          meta: { title: 'menu2' }
        }
      ]
    },
  
    {
      path: 'external-link',
      component: Layout,
      children: [
        {
          path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
          meta: { title: 'External Link', icon: 'link' }
        }
      ]
    },
  
    // 404 page must be placed at the end !!!
    { path: '*', redirect: '/404', hidden: true }
  ];
  export const asyncRoutes = [
    {
      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/nested/menu2/index'),
          name: 'PagePermission',
          meta: {
            title: 'Page Permission',
            roles: ['admin'] // or you can only set roles in sub nav
          }
        },
        {
          path: 'directive',
          component: () => import('@/views/nested/menu2/index'),
          name: 'DirectivePermission',
          meta: {
            title: 'Directive Permission'
            // if do not set roles, means: this page does not require permission
          }
        },
        {
          path: 'role',
          component: () => import('@/views/nested/menu2/index'),
          name: 'RolePermission',
          meta: {
            title: 'Role Permission',
            roles: ['admin']
          }
        }
      ]
    }
  ];
  
  /**
   * @description 创建路由并将路由序列挂载
   * @mode 'history' || 'hash' 路由模式
   * @scrollBehavior 滚动行为,这个功能只在 HTML5 history 模式下可用。
   * @routes 传入路由序列
   * */
  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;
  