index.js 552 Bytes
import Vue from 'vue';
import Router from 'vue-router';
import routes from '../pages';

Vue.use(Router);

export function createRouter() {
  const route = new Router({
    mode: 'history',
    routes,
    scrollBehavior(to, from, savedPosition) {
      console.log(to.name)
      if (savedPosition) {
        return savedPosition;
      } else {
        return { x: 0, y: 0 };
      }
    }
  });

  route.beforeEach((to, from, next) => {
    if (!to.matched.length) {
      return next({name: 'error.404'});
    }
    next();
  });

  return route;
}