text: import Vue from 'vue'
  import Router from 'vue-router'
  import Home from './views/Home.vue'
  import store from './store';
  
  Vue.use(Router)
  
  const router = new Router({
    mode: 'history',
    base: process.env.BASE_URL,
    routes: [
      {
        path: '/',
        name: 'home',
        component: Home
      },
      // {
      //   path: '*',
      //   name: 'home',
      //   component: Home
      // },
      {
        path: '/login',
        name: 'login',
        // 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/Login.vue'),
        meta: {
          requiresGuest: true
        }
      },
  
      {
        path: '/register',
        name: 'register',
        // 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/Register.vue'),
        meta: {
          requiresGuest: true
        }
      },
  
      {
        path: '/dashboard',
        name: 'dashboard',
        // 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/Dashboard.vue'),
        meta: {
          requiresAuth: true
        }
      },
  
      {
        path: '/profile',
        name: 'profile',
        // 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/Profile.vue'),
        meta: {
          requiresAuth: true
        }
      },
      {
        path: '/blog',
        name: 'blog',
        // 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/Blog.vue'),
        meta: {
          requiresAuth: true
        }
      }
  
    ]
  });
  
  router.beforeEach((to, from, next) => {
    if (to.matched.some(record => record.meta.requiresAuth)) {
      if (!store.getters.isLoggedIn) {
        // Redirect to the login Page
        next('/login');
      }
      else {
        next();
      }
    }
    else if (to.matched.some(record => record.meta.requiresGuest)) {
      if (store.getters.isLoggedIn) {
        // Redirect to the login Page
        next('/profile');
      }
      else {
        next();
      }
    }
    else {
      next();
    }
  
  });
  export default router;
  