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',
          path: 'Role',
          component:() => import('@/components/permissions/role'),
          name: '角色介绍',
        },
        {
          path: '/permissions/module',
          path: 'Module',
          component:() => import('@/components/permissions/module'),
          name: '模块介绍',
        },
        {
          path: '/permissions/user',
          path: 'User',
          component:() => import('@/components/permissions/user'),
          name: '角色管理',
        },
        {
          path: '/permissions/operate',
          path: 'Operate',
          component:() => import('@/components/permissions/operate'),
          name: '操作日志',
        },
        {
          path: '/permissions/login',
          path: 'Login',
          component:() => import('@/components/permissions/login'),
          name: '登录日志',
        },
      ]
    },
  ]
})

const defaultTitle = '投诉管理系统'
router.beforeEach((to, from, next) => {
  document.title = to.meta.title ? to.meta.title : defaultTitle
  next()
})
export default router
