first commit
This commit is contained in:
51
src/router/index.js
Normal file
51
src/router/index.js
Normal file
@@ -0,0 +1,51 @@
|
||||
import Vue from 'vue'
|
||||
import VueRouter from 'vue-router'
|
||||
import store from '@/store';
|
||||
|
||||
import DefaultLayout from '@/layouts/default'
|
||||
|
||||
Vue.use(VueRouter)
|
||||
|
||||
// route level code-splitting
|
||||
// this generates a separate chunk (about.[hash].js) for this route
|
||||
// which is lazy-loaded when the route is visited.
|
||||
const routes = [
|
||||
{
|
||||
path: '/',
|
||||
name: 'DefaultLayout',
|
||||
component: DefaultLayout,
|
||||
children: [
|
||||
{
|
||||
path: '/content/list',
|
||||
name: 'ContentList',
|
||||
component: () => import(/* webpackChunkName: "content" */ '../views/Content/ContentList.vue')
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
path: '/login',
|
||||
name: 'Login',
|
||||
component: () => import(/* webpackChunkName: "login" */ '../views/Login/Login.vue')
|
||||
},
|
||||
]
|
||||
|
||||
const router = new VueRouter({
|
||||
mode: 'history',
|
||||
base: process.env.BASE_URL,
|
||||
routes
|
||||
})
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
if (to.path !== '/login') {
|
||||
const isAuthenticated = store.getters['accountStore/isAuthenticated']
|
||||
if (isAuthenticated) {
|
||||
next();
|
||||
} else {
|
||||
next('/login?redirect=' + to.fullPath)
|
||||
}
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
})
|
||||
|
||||
export default router
|
||||
Reference in New Issue
Block a user