vue router implemented

This commit is contained in:
carodej
2020-04-07 14:48:29 +02:00
parent bde58fbf60
commit ae4353cc4b
21 changed files with 722 additions and 998 deletions
+58 -7
View File
@@ -1,10 +1,14 @@
import Vue from 'vue'
import Router from 'vue-router'
import store from '@/store'
import Index from './views/Index'
import SignUp from './views/SignUp'
import ForgottenPassword from './views/ForgottenPassword'
//import ForgottenPassword from './views/ForgottenPassword'
import Index from './views/Auth/SignIn'
import SignUp from './views/Auth/SignUp'
import ForgottenPassword from './views/Auth/ForgottenPassword'
import CreateNewPassword from './views/Auth/CreateNewPassword'
import Files from './views/Files'
import Profile from './views/Profile'
Vue.use(Router)
@@ -12,25 +16,53 @@ const router = new Router({
mode: 'history',
routes: [
{
name: 'index',
name: 'SignIn',
path: '/',
component: Index,
meta: {
requiresAuth: false
},
},
{
name: 'SignUp',
path: '/sign-up',
component: SignUp,
meta: {
requiresAuth: false
},
},
{
name: 'ForgottenPassword',
path: '/forgotten-password',
component: ForgottenPassword,
meta: {
requiresAuth: false
},
},
/*{
{
name: 'CreateNewPassword',
path: '/create-new-password',
component: CreateNewPassword,
},*/
meta: {
requiresAuth: false
},
},
{
name: 'Files',
path: '/files',
component: Files,
meta: {
requiresAuth: true
},
},
{
name: 'Profile',
path: '/profile',
component: Profile,
meta: {
requiresAuth: true
},
},
],
scrollBehavior(to, from, savedPosition) {
@@ -39,6 +71,25 @@ const router = new Router({
} else {
return {x: 0, y: 0}
}
},
})
router.beforeEach((to, from, next) => {
if (to.matched.some(record => record.meta.requiresAuth)) {
// this route requires auth, check if logged in
// if not, redirect to login page.
if ( ! store.getters.isLogged || ! config.hasAuthCookie) {
next({
name: 'SignIn',
query: { redirect: to.fullPath }
})
} else {
next()
}
} else {
next() // make sure to always call next()!
}
})