import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)

const router = new Router({
  // mode: 'history',
  routes: [
    {
      path: '/',
      redirect: '/home'
    },
    {
      path: '/home',
      name: 'Home',
      component: () => import('@/components/home/index'),
      meta: {
        title: '投诉管理系统'
      },
    },
    {
      path: '/permissions',
      redirect: 'Permissions',
      component:() => import('@/components/permissions/index'),
      children: [
        {
          path: '/permissions/role',
          name: 'Role',
          component:() => import('@/components/permissions/role'),
          meta: {
            title: '角色介绍'
          },
        },
        {
          path: '/permissions/module',
          name: 'Module',
          component:() => import('@/components/permissions/module'),
          meta: {
            title: '模块介绍'
          },
        },
        {
          path: '/permissions/user',
          name: 'User',
          component:() => import('@/components/permissions/user'),
          meta: {
            title: '角色管理'
          },
        },
        {
          path: '/permissions/operate',
          name: 'Operate',
          component:() => import('@/components/permissions/operate'),
          meta: {
            title: '操作日志'
          },
        },
        {
          path: '/permissions/login',
          name: 'Login',
          component:() => import('@/components/permissions/login'),
          meta: {
            title: '登录日志'
          },
        },
      ]
    },
  ]
})

const defaultTitle = '权限和日志管理'
router.beforeEach((to, from, next) => {
  document.title = to.meta.title ? to.meta.title : defaultTitle
  next()
})
export default router
