blob: 698aa700efe9ffd0e0c09a45ea37b6b556350b8b [file] [log] [blame]
Derick Montaguea2988f42020-01-17 13:46:30 -06001import Vue from "vue";
2import VueRouter from "vue-router";
Derick Montaguee080a1a2019-12-04 16:30:08 -06003import store from "../store/index";
4import AppLayout from "../layouts/AppLayout.vue";
Derick Montaguea2988f42020-01-17 13:46:30 -06005
6Vue.use(VueRouter);
7
8const routes = [
9 {
10 path: "/",
Derick Montaguee080a1a2019-12-04 16:30:08 -060011 name: "",
12 meta: {
13 requiresAuth: true
14 },
15 component: AppLayout,
16 children: [
17 {
18 path: "",
19 component: () => import("@/views/Overview")
20 },
21 {
22 path: "/access-control/local-user-management",
23 name: "local-users",
24 component: () => import("@/views/AccessControl/LocalUserManagement")
25 }
26 ]
Derick Montaguea2988f42020-01-17 13:46:30 -060027 },
28 {
Derick Montaguee080a1a2019-12-04 16:30:08 -060029 path: "/login",
30 name: "login",
31 component: () => import("@/views/Login")
Derick Montaguea2988f42020-01-17 13:46:30 -060032 }
Derick Montaguea2988f42020-01-17 13:46:30 -060033];
34
35const router = new VueRouter({
36 mode: "history",
37 base: process.env.BASE_URL,
38 routes,
39 linkExactActiveClass: "nav__link--current"
40});
41
Derick Montaguee080a1a2019-12-04 16:30:08 -060042router.beforeEach((to, from, next) => {
43 if (to.matched.some(record => record.meta.requiresAuth)) {
44 if (store.getters["authentication/isLoggedIn"]) {
45 next();
46 return;
47 }
48 next("/login");
49 } else {
50 next();
51 }
52});
53
Derick Montaguea2988f42020-01-17 13:46:30 -060054export default router;