import Vue from 'vue'
import VueRouter from 'vue-router'
import store from '../store'



Vue.use(VueRouter)

const routes = [
    {
      path: '/',
      name: 'Layout',
      redirect:'/OKRpage',
      component: () => import(/* webpackChunkName: "about" */ '../Layout.vue'),
      children:[
        // {
        //   path: 'home',
        //   name: 'Home',
        //   component: Home
        // },
        {
          path: 'okrlist',
          name: 'OKRlist',
          // route level code-splitting
          // this generates a separate chunk (about.[hash].js) for this route
          // which is lazy-loaded when the route is visited.
          component: () => import(/* webpackChunkName: "about" */ '../views/OKRList.vue'),
          meta:{
            isLogin:true
          }
        },
        {
          path: 'OKRpage',
          name: 'OKRpage',
          // route level code-splitting
          // this generates a separate chunk (about.[hash].js) for this route
          // which is lazy-loaded when the route is visited.
          component: () => import(/* webpackChunkName: "about" */ '../views/OKRpage.vue'),
          meta:{
            isLogin:true
          }
        },
        {
          path: 'Feedback',
          name: 'Feedback',
          // route level code-splitting
          // this generates a separate chunk (about.[hash].js) for this route
          // which is lazy-loaded when the route is visited.
          component: () => import(/* webpackChunkName: "about" */ '../views/Feedback.vue'),
          meta:{
            isLogin:true
          }
        },
      ]
    },
    {
        path: '/login',
        name: 'Login',       
        component: () => import(/* webpackChunkName: "about" */ '../views/Login.vue')
     },
      {
        path: '/transfer-local',
        name: 'transferLocal',       
        component: () => import(/* webpackChunkName: "about" */ '../views/TransferLocal.vue')
     }
  // {
  //   path: '/about',
  //   name: 'About',
  //   // route level code-splitting
  //   // this generates a separate chunk (about.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  // }
]

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

router.beforeEach((to,from,next)=>{
  let userInfo=JSON.parse(localStorage.getItem('Login_Userinfo'))
  console.log(to,from,userInfo)
  if(to.matched.some(res=>res.meta.isLogin)){//判断是否需要登录
      if (userInfo) {
        console.log('登陆跳转---tolist')
          next();
      }else{
          next({
              path:"/login",
              // query:{
              //     redirect:to.fullPath
              // }
          });
      }

  }else{
      next()
  }
});

export default router
