import Vue from 'vue'
import VueRouter from 'vue-router'
import NProgress from 'muse-ui-progress';

Vue.use(VueRouter);

let NPconfig = {
    zIndex: 2000,          // progress z-index
    top: 0,                // position fixed top
    speed: 300,            // progress speed
    color: '#E75296',      // color
    size: 2,               // progress size
    className: ''          // progress custom class
};
Vue.use(NProgress,NPconfig);

const routes = [
    {
        path: '/',
        name: '',
        component: () => import( '../page/index.vue'),
        meta: {index: 0},//meta对象的index用来定义当前路由的层级,由小到大,由低到高
        children: [
            {
                path: '/',
                name: 'main',
                meta: {
                    title: '预约课程',
                    index: 1
                },
                component: () => import( '../page/mainpage.vue')
            },
            {
                path: '/sport',
                name: 'sport',
                meta: {
                    title: '运动',
                    index: 2
                },
                component: () => import( '../page/sport.vue')
            },  {
                path: '/record',
                name: 'record',
                meta: {
                    title: '预约记录',
                    index: 1
                },
                component: () => import( '../page/record.vue')
            }, {
                path: '/mine',
                name: 'mine',
                meta: {
                    title: '我的',
                    index: 1
                },
                component: () => import( '../page/mine.vue')
            },{
                path: '/lesson',
                name: 'lesson',
                meta: {
                    title: '课程表',
                    index: 1
                },
                component: () => import( '../page/lesson.vue')
            },
        ]
    },
    {
        path: '/login',
        name: 'login',
        meta: {
            title: '登陆',
            index: 1
        },
        component: () => import( '../page/login.vue')
    }, {
        path: '/test',
        name: 'test',
        meta: {
            title: 'test',
            index: 1
        },
        component: () => import( '../page/test.vue')
    }, {
        path: '*',
        name: 'notFound',
        meta: {
            title: '404',
            index: 3
        },
        component: () => import( '../page/notFound.vue')
    },
];

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

// 路由守卫
router.beforeEach((to,from,next)=>{
    NProgress.start();
    next();
});

router.afterEach(() => {
    NProgress.done()
});

export default router
