Skip to content
Snippets Groups Projects
Select Git revision
  • 41f82804dd8b9b4a20694933421c05b2d1b33179
  • development default protected
  • temp
  • master protected
  • #36
  • #24
  • #39
  • #38
  • #37
  • #35
  • #34
  • #33
  • #32
  • #31
  • #21
  • #22
  • #20
  • #23
  • #19
  • #17
  • #16
21 results

index.js

Blame
  • index.js 903 B
    import Vue from 'vue';
    import VueRouter from 'vue-router';
    
    import Store from '@/store/index';
    import APISetting from '@/settings/api';
    import Login from '@/views/Login.vue';
    
    Vue.use(VueRouter);
    
    const routes = [
      {
        path: '/',
        name: 'login',
        component: Login,
      },
      {
        path: '/main',
        name: 'main',
        component: () => import('@/views/Main.vue'),
      },
    ];
    
    const router = new VueRouter({
      mode: 'history',
      base: process.env.BASE_URL,
      routes,
    });
    
    router.beforeEach(async (to, from, next) => {
      Store.commit('setPageStartLoading');
    
      const res = await fetch(APISetting.endpoints.auth.check, APISetting.settings.get);
      if (res.status === 200) {
        const json = await res.json();
        Store.commit('setLogin', json.user);
      } else {
        Store.commit('setLogout');
      }
    
      next();
    });
    
    router.afterEach(() => {
      Store.commit('setPageFinishLoading');
    });
    
    export default router;