import Vue from 'vue'
import Router from 'vue-router'
import { getToken } from '@/utils/auth'
Vue.use(Router)

const router = new Router({
  routes: [
    {
      path: '/',
      name:'login',
      component: () => import('@/page/login'), 
    },
    {
      path: '/login',
      name:'login',
      component: () => import('@/page/login'), 
    },
    { path: '/main', component:()=> import('@/page/main'),
      children: [
          {
            path: 'chat',
            component:()=> import('@/page/main/chat/chat.vue'),
            beforeEnter: (to, from, next) => {
              if(getToken()){
                next()
              }else{
                next(false)
              }
            }
          },
          {
            path: 'friend',
            component:()=> import('@/page/main/friend/friend.vue')
          },
          {
            path: 'my',
            component:()=> import('@/page/main/friend/friend.vue') 
          }
      ]
    }
  ],
  linkActiveClass: 'active'
})
router.push({ path: '/login' });
export default router