My Vue.js application is set up with vue-router as shown below. index.html
<p>
<router-link to="/" exact> Home </router-link>
<router-link to="/about"> About </router-link>
<router-link to="/contact"> Contact </router-link>
<router-link to="/login"> Login </router-link>
<router-link to="/register"> Register </router-link>
</p>
<router-view></router-view>
The routes are defined in the /routes.js
file:
import VueRouter from 'vue-router';
let routes = [
{
path: '/',
component: require('./components/Home.vue')
},
{
path: '/about',
component: require('./components/About.vue')
},
{
path: '/login',
component: require('./components/Login.vue')
},
{
path: '/register',
component: require('./components/Register.vue')
}
];
export default new VueRouter({
mode: 'history',
routes
});
In my index.js
file, where I initialize the app, I am considering implementing something within the created(){}
module. However, I'm unsure about the specifics.
I have the capability to manage sessions and would like to restrict access to a page based on session existence. Can someone advise on how this can be achieved?