I'm struggling to do a check against a store variable/property in the route beforeEach guard.. I cannot seem to figure out how to access the store's properties..
My code :
import Vue from 'vue'
import Router from 'vue-router'
import store from "@/components/store.js"
... other imports..
Vue.use(Router);
const routes = [
{ path: '/', component: NluEditor },
{ path: '/nlueditor', component: NluEditor },
{ path: '/login', component: Login },
{ path: '/logout', component: Logout}
];
const router = new Router({
routes
});
router.beforeEach((to, from, next) => {
if(to.path != '/login') {
console.log(store)
if (store.state.loggedInUser) { // cannot seem to access store ?
console.log("You are logged in :) Go to requested page ")
next()
}
else {
console.log("Not logged in.. redirecting....")
next('login');
}
}
})
const app = new Vue({
el: '#app',
router,
store,
render: h => h(App)
})