xref: /openbmc/webui-vue/src/router/index.js (revision 463a5706)
1import Vue from "vue";
2import VueRouter from "vue-router";
3import store from "../store/index";
4import AppLayout from "../layouts/AppLayout.vue";
5
6Vue.use(VueRouter);
7
8const routes = [
9  {
10    path: "/",
11    name: "",
12    meta: {
13      requiresAuth: true
14    },
15    component: AppLayout,
16    children: [
17      {
18        path: "",
19        component: () => import("@/views/Overview"),
20        meta: {
21          title: "Server Overview"
22        }
23      },
24      {
25        path: "/access-control/local-user-management",
26        name: "local-users",
27        component: () => import("@/views/AccessControl/LocalUserManagement"),
28        meta: {
29          title: "Manage Local Users"
30        }
31      }
32    ]
33  },
34  {
35    path: "/login",
36    name: "login",
37    component: () => import("@/views/Login"),
38    meta: {
39      title: "Login"
40    }
41  }
42];
43
44const router = new VueRouter({
45  mode: "history",
46  base: process.env.BASE_URL,
47  routes,
48  linkExactActiveClass: "nav__link--current"
49});
50
51router.beforeEach((to, from, next) => {
52  if (to.matched.some(record => record.meta.requiresAuth)) {
53    if (store.getters["authentication/isLoggedIn"]) {
54      next();
55      return;
56    }
57    next("/login");
58  } else {
59    next();
60  }
61});
62
63export default router;
64