import Vue from 'vue'
import Router from 'vue-router'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import login from '@/components/login'
import register from '@/components/register'
import eventCenter from '@/components/pages/race/eventCenter'
import addRace from '@/components/pages/race/addRace'
import anliDetail from '@/components/pages/race/eventCenter/anliDetail'
import demo from '@/components/pages/demo'
import anliList from '@/components/pages/munAdmin/anliList'
import data from '@/components/pages/munAdmin/data'
import notice from '@/components/pages/munAdmin/notice'
import score from '@/components/pages/munAdmin/score'
import user from '@/components/pages/munAdmin/user'
import county from '@/components/pages/munAdmin/county'
import school from '@/components/pages/munAdmin/school'


Vue.use(Router).use(ElementUI)

const router = new Router({
    routes: [{
            path: '/login',
            name: 'login',
            component: login,
            meta: {
                requireAuth: '' // 不需要鉴权
            }
        }, {
            path: '/register',
            name: 'register',
            component: register,
            meta: {
                requireAuth: false // 不需要鉴权
            }
        }, {
            path: '/eventCenter',
            name: 'eventCenter',
            component: eventCenter,
            meta: {
                requireAuth: true // 不需要鉴权
            }
        }, {
            path: '/addRace',
            name: 'addRace',
            component: addRace,
            meta: {
                requireAuth: true // 不需要鉴权
            }
        }, {
            path: '/anliDetail',
            name: 'anliDetail',
            component: anliDetail,
            meta: {
                requireAuth: true // 不需要鉴权
            }
        }, {
            path: '/demo',
            name: 'demo',
            component: demo,
            meta: {
                requireAuth: false // 不需要鉴权
            }
        }, {
            path: '/anliList',
            name: 'anliList',
            component: anliList,
            meta: {
                requireAuth: true // 不需要鉴权
            }
        },
        {
            path: '/data',
            name: 'data',
            component: data,
            meta: {
                requireAuth: true // 不需要鉴权
            }
        },
        {
            path: '/notice',
            name: 'notice',
            component: notice,
            meta: {
                requireAuth: true // 不需要鉴权
            }
        },
        {
            path: '/score',
            name: 'score',
            component: score,
            meta: {
                requireAuth: true // 不需要鉴权
            }
        },
        {
            path: '/user',
            name: 'user',
            component: user,
            meta: {
                requireAuth: true // 不需要鉴权
            }
        }, {
            path: '/county',
            name: 'county',
            component: county,
            meta: {
                requireAuth: true // 不需要鉴权
            }
        }, {
            path: '/school',
            name: 'school',
            component: school,
            meta: {
                requireAuth: true // 不需要鉴权
            }
        },
    ]
})

router.beforeEach((to, from, next) => {
    if (to.matched.length === 0) {
        from.name ? next({
            name: from.name
        }) : next('/login');
    } else {
        next();
    }
})

export default router;