import store from '@/store/index';

const checkLogin = (router, func) => {
  router.beforeEach(async (to, form, next) => {
    if (to.name == 'index') {
      let token = localStorage.getItem('token');
      if (token) {
        next();
      } else {
        next({ name: 'login' });
      }
    }
    let res = await store.dispatch('login/toGetUser', func ? func : null);
    next();
  });
};
export default checkLogin;
