2020-01-30 15:45:49 +09:00
|
|
|
import Vue from 'vue'
|
|
|
|
import VueRouter from 'vue-router'
|
2020-04-28 20:11:49 +09:00
|
|
|
import store from "../store";
|
2020-01-30 15:45:49 +09:00
|
|
|
|
2020-02-20 12:07:13 +09:00
|
|
|
Vue.use(VueRouter);
|
2020-01-30 15:45:49 +09:00
|
|
|
|
|
|
|
const routes = [
|
2020-02-20 12:07:13 +09:00
|
|
|
{
|
|
|
|
path: '/clients',
|
|
|
|
name: 'clients',
|
|
|
|
component: function () {
|
|
|
|
return import(/* webpackChunkName: "Clients" */ '../views/Clients.vue')
|
|
|
|
},
|
2020-04-28 20:11:49 +09:00
|
|
|
meta: {
|
|
|
|
requiresAuth: true
|
|
|
|
}
|
2020-02-20 12:07:13 +09:00
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '/server',
|
|
|
|
name: 'server',
|
|
|
|
component: function () {
|
|
|
|
return import(/* webpackChunkName: "Server" */ '../views/Server.vue')
|
|
|
|
},
|
2020-04-28 20:11:49 +09:00
|
|
|
meta: {
|
|
|
|
requiresAuth: true
|
|
|
|
}
|
2020-01-30 15:45:49 +09:00
|
|
|
}
|
2020-02-20 12:07:13 +09:00
|
|
|
];
|
2020-01-30 15:45:49 +09:00
|
|
|
|
|
|
|
const router = new VueRouter({
|
|
|
|
mode: 'history',
|
|
|
|
base: process.env.BASE_URL,
|
|
|
|
routes
|
2020-02-20 12:07:13 +09:00
|
|
|
});
|
2020-01-30 15:45:49 +09:00
|
|
|
|
2020-04-28 20:11:49 +09:00
|
|
|
router.beforeEach((to, from, next) => {
|
|
|
|
if(to.matched.some(record => record.meta.requiresAuth)) {
|
|
|
|
if (store.getters["auth/isAuthenticated"]) {
|
|
|
|
next()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
next('/')
|
|
|
|
} else {
|
|
|
|
next()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-01-30 15:45:49 +09:00
|
|
|
export default router
|