import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
    {
        path: '/login',
        name: 'login',
        component: () => import('@/views/login/index')
    },
    {
        path: '/',
        name: 'Layout',
        component: () => import('@/components/layout/index'),
        children: [{
            path: 'vehicleManagement',
            component: () => import('@/views/vehicleManagement')
        }, {
            path: 'groupManagement',
            component: () => import('@/views/groupManagement')
        }, {
            path: 'groupManagement/detail',
            component: () => import('@/views/groupManagement/detail')
        }, {
            path: 'issueManagement',
            component: () => import('@/views/issueManagement')
        }, {
            path: 'issueManagement/detail',
            component: () => import('@/views/issueManagement/detail')
        }, {
            path: 'dateTask',
            component: () => import('@/views/dateTask')
        }, {
            path: 'sendCommand',
            component: () => import('@/views/sendCommand')
        }, {
            path: 'configurationManagement',
            component: () => import('@/views/configurationManagement')
        }, 
        {
            path: 'permission',
            component: () => import('@/views/permission'),
            redirect:'/user',
            children:[
                {
                    path: '/user',
                    component: () => import('@/views/userList'),
                },{
                    path: '/role',
                    component: () => import('@/views/roleList'),
                },{
                    path: '/roleDetail',
                    component: () => import('@/views/roleDetail'),
                }
            ],
        }, 
        {
            path: '*',
            redirect: '/vehicleManagement'
        }, {
            path: '/',
            redirect: '/vehicleManagement'
        }]
    }
]

const router = new VueRouter({
    mode: 'hash',
    base: process.env.BASE_URL,
    routes
})

// 解决ElementUI导航栏中的vue-router在3.0版本以上重复点菜单报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}

export default router
