In my main.js file, I have set up the following configuration:
import Vue from 'vue'
import App from './App.vue'
import VueRouter from 'vue-router'
import Home from './views/Home.vue'
import Login from './views/Login.vue'
import Profile from './views/Profile.vue'
import Simulations from './views/Simulations.vue'
import VueSimpleAlert from "vue-simple-alert"
import StatisticPage from './views/StatisticPage.vue'
import VueSession from 'vue-session'
import Users from './views/Users.vue'
Vue.use(VueSimpleAlert)
Vue.use(VueRouter)
Vue.use(VueSession)
Vue.config.productionTip = false
const routes = [
{path: '/', name:'Login', component: Login },
{path: '/users', name:'Users', component: Users},
{path :'/home', name:'Home', component: Home},
{path: '/subject/:Pid', name: 'Profile', component: Profile},
{path: '/subject/:Pid/simulations', name:'Simulations', component: Simulations},
{path: '/subject/:Pid/simulations/:Sid/statistics', name:'Statistics', component: StatisticPage}
]
const router = new VueRouter({
routes,
mode: 'history'
})
router.beforeEach((to, from, next) => {
if(to.name !== 'Login'){
if(this.$session.get('token')){
next()
}else{
next({ name: 'Login'})
next()
}
}else{
next()
}
})
new Vue({
router,
render: h => h(App),
}).$mount('#app')
export default router
I am facing an issue where I am unable to access the session information in the router as I keep receiving an error stating that $session is undefined. Can someone guide me on how to properly access the session information within the router?