import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/Login.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/login',
    name: 'Login',
    component: Login,
  },
  {
    path: '/MLargeScreen/index',
    name: 'MLargeScreen/index',
    component: () => import('../views/MLargeScreen/index.vue'),
  },
  //路由重定向
  {
    name: 'default',
    path: '*',
    redirect: '/login'
  },
]

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

//全局守卫
router.beforeEach((to, from, next) => {
  //判断路由是否需要守卫
  //meta数据
  if (to.meta.auth) {
    //是否登录
    if (window.isLogin) {
      next();
    } else {
      next('/login?redirect=' + to.fullPath);
    }
  } else {
    next();
  }
})
export default router
