1
0
Fork 0
mirror of https://github.com/VueTorrent/VueTorrent.git synced 2025-03-26 11:30:37 +03:00
VueTorrent/src/router.js

51 lines
1.3 KiB
JavaScript
Raw Normal View History

2019-04-15 16:50:38 +02:00
import Vue from 'vue'
import Router from 'vue-router'
import Dashboard from '@/views/Dashboard.vue'
import Login from '@/views/Login.vue'
import store from '@/store'
2019-04-15 16:50:38 +02:00
Vue.use(Router)
const router = new Router({
2020-05-20 14:49:42 +02:00
mode: 'history',
base: process.env.BASE_URL,
routes: [
{
path: '/',
name: 'dashboard',
component: Dashboard
},
{
path: '/login',
name: 'login',
component: Login,
meta: {
public: true, // Allow access to even if not logged in
onlyWhenLoggedOut: true
}
2020-05-20 14:49:42 +02:00
}
]
2019-04-15 16:50:38 +02:00
})
router.beforeEach((to, from, next) => {
const isPublic = to.matched.some(record => record.meta.public)
const onlyWhenLoggedOut = to.matched.some(record => record.meta.onlyWhenLoggedOut)
const loggedIn = store.state.authenticated
if (!isPublic && !loggedIn) {
return next({
path:'/login',
query: {redirect: to.fullPath} // Store the full path to redirect the user to after login
});
}
// Do not allow user to visit login page or register page if they are logged in
if (loggedIn && onlyWhenLoggedOut) {
return next('/')
}
next();
})
export default router;