import Vue from 'vue'; import VueRouter from 'vue-router'; import store from './store.js'; import editor from './views/editor.vue'; import login from './views/login.vue'; import focusDirectives from './utils/focus.js'; import dataTypes from './dataTypes.js'; import utils from './utils/utils.js'; const Item = dataTypes.Item; const Category = dataTypes.Category; const List = dataTypes.List; const Library = dataTypes.Library; var init = function () { window.app = new Vue({ router, store, data: { path: '', fatal: '', }, watch: { $route(to, from) { this.path = to.path; }, }, mounted() { this.path = router.currentRoute.path; }, }).$mount('#lp'); }; Vue.use(VueRouter); window.Vue = Vue; // surfacing Vue globally for utils methods window.bus = new Vue(); // global event bus window.router = new VueRouter({ mode: 'history', routes: [ { path: '/login', component: login }, { path: '/editor', component: editor }, { path: '*', component: editor }, ], }); bus.$on('unauthorized', (error) => { window.location = '/login'; }); store.dispatch('init') .then(() => { init(); }) .catch((error) => { if (!store.state.library) { router.push('/login'); } init(); });