import Vue from 'vue';
import Router from 'vue-router';
import ddLogin from '../assets/js/ddLogin';
import store from '../vuex/index';

Vue.use(Router);

let router = new Router({
    routes: [
        {
            path: '/',
            name: 'index',
            component: ()=>import('@/pages/index.vue'),
            children:[
                {
                    path: 'folder',
                    name:'folder',
                    component: ()=>import('@/pages/folder.vue'),
                },
                {
                    path: 'folder2',
                    name:'folder2',
                    component: ()=>import('@/pages/folder2.vue'),
                },
                {
                    path: 'wangeditor',
                    name:'wangeditor',
                    component: ()=>import('@/pages/wangeditor.vue'),
                },
                {
                    path: 'markdown',
                    name:'markdown',
                    component: ()=>import('@/pages/markdown.vue'),
                },
                {
                    path: 'test',
                    name:'test',
                    component: ()=>import('@/pages/test.vue'),
                },
            ]
        },
    ]
});

router.beforeEach((to, from, next) => {
    //没有token则去获取
    let token = localStorage.getItem('doc_phone_token');
    if(!token){
        ddLogin.getCode(()=> next());
    }else{
        next();
    }
});

export default router;