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

Vue.use(VueRouter)

const routes = [
    {
        path: '/',
        name: 'Layout',
        component: () => import('@/components/layout/index'),
        children: [
        {
            path: 'groupManagement',
            meta: {
                title: 'Group Management'
            },
            component: () => import('@/components/component'),
            redirect:'/groupManagement',
            children: [
                {
                    path: '/groupManagement',
                    meta: {
                        title: ''
                    },
                    component: () => import('@/views/groupManagement')
                },
                {
                    path: '/groupManagement/addVin',
                    meta: {
                        title: 'Add Vehicle'
                    },
                    component: () => import('@/views/groupManagement/addVin')
                },
                {
                    path: '/groupManagement/detail',
                    meta: {
                        title: 'Detail'
                    },
                    component: () => import('@/views/groupManagement/detail')
                }
            ]
        },
        {
            path: 'ticketManagement',
            meta: {
                title: 'Ticket Management'
            },
            component: () => import('@/components/component'),
            redirect:'/ticketManagement',
            children: [
                {
                    path: '/ticketManagement',
                    meta: {
                        title: ''
                    },
                    component: () => import('@/views/ticketManagement')
                },
                {
                    path: '/ticketManagement/detail',
                    meta: {
                        title: 'Detail'
                    },
                    component: () => import('@/views/ticketManagement/detail')
                },
            ]
        },
        {
            path: 'configurationManagement',
            meta: {
                title: 'Configuration Management'
            },
            component: () => import('@/views/configurationManagement')
        }, 
        {
            path: 'permissionManagement',
            meta: {
                title: 'Permission Management'
            },
            component: () => import('@/views/permissionManagement'),
            redirect:'/permissionManagement/userList',
            children:[
                {
                    path: '/permissionManagement/userList',
                    meta: {
                        title: 'User List'
                    },
                    component: () => import('@/views/permissionManagement/user'),
                },{
                    path: '/permissionManagement/roleList',
                    meta: {
                        title: 'Role List'
                    },
                    component: () => import('@/views/permissionManagement/role'),
                },{
                    path: '/permissionManagement/resourceConfig',
                    meta: {
                        title: 'Resource Config'
                    },
                    component: () => import('@/views/permissionManagement/resource'),
                }
            ],
        },{
            path: '/datasourceManagement',
            meta: {
                title: 'Data Source Management'
            },
            component: () => import('@/views/datasourceManagement')
        }, 
        {
            path: '*',
            redirect: '/groupManagement'
        }, {
            path: '/',
            redirect: '/groupManagement'
        }]
    }
]

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
