Mercurial > gemma
diff client/src/router.js @ 13:88d0d60924cf
Move vuejs app into subdir `client`
Using a subdirectory for the web application keeps more structure
in the repo.
author | Bernhard Reiter <bernhard@intevation.de> |
---|---|
date | Wed, 20 Jun 2018 17:02:06 +0200 |
parents | src/router.js@7c1bde663c8e |
children | 7ba0a77fd679 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/src/router.js Wed Jun 20 17:02:06 2018 +0200 @@ -0,0 +1,43 @@ +import Vue from "vue"; +import Router from "vue-router"; +import Login from "./views/Login.vue"; +import Main from "./views/Main.vue"; +import store from "./store"; + +Vue.use(Router); + +const router = new Router({ + routes: [ + { + path: "/login", + name: "login", + component: Login + }, + { + path: "/", + name: "main", + component: Main, + meta: { + requiresAuth: true + } + }, + { + path: "*", + component: Login + } + ] +}); + +router.beforeEach((to, from, next) => { + const requiresAuth = to.matched.some(record => record.meta.requiresAuth); + const currentUser = store.getters["user/authenticated"]; + if (requiresAuth && !currentUser) { + next("/login"); + } else if (requiresAuth && currentUser) { + next(); + } else { + next(); + } +}); + +export default router;