index.js 1.44 KB
import Vue from 'vue';
import Router from 'vue-router';
import paths from './paths';
import NProgress from 'nprogress';
import 'nprogress/nprogress.css';
import store from '@/store/store'

Vue.use(Router);
const router = new Router({
  base: '/',
  mode: 'history',
  linkActiveClass: 'active',
  routes: paths,
  scrollBehavior() {
    window.scrollTo(0, 0);
  }
});

// const scrollableElementId = 'content' // You should change this
// const scrollPositions = Object.create(null)

// router.beforeEach((to, from, next) => {
//   let element = document.getElementById(scrollableElementId)
//   if (element !== null) {
//     scrollPositions[from.name] = element.scrollTop
//   }

//   next()
// })

// window.addEventListener('popstate', () => {
//   let currentRouteName = router.history.current.name

//   let element = document.getElementById(scrollableElementId)
//   if (element !== null && currentRouteName in scrollPositions) {
//     setTimeout(() => element.scrollTop = scrollPositions[currentRouteName], 50)
//   }
// })

// router gards
// router.beforeEach((to, from, next) => {
//   NProgress.start();
//   next();
// });

// router.beforeEach((to, from, next) => {
//   var token = store.getters.GET_TOKEN;
//   if (!token) {
//     console.log("yes yes yes")
//     window.getApp.$emit("APP_LOGOUT");
//   } else {
//     NProgress.start();
//     next();
//   }
// });

router.afterEach((to, from) => {
  // ...
  NProgress.done();
});

export default router;