Mercurial > gemma
view client/src/router.js @ 18:eef728039900
merge
author | Thomas Junk <thomas.junk@intevation.de> |
---|---|
date | Thu, 21 Jun 2018 11:19:29 +0200 |
parents | 88d0d60924cf |
children | 7ba0a77fd679 |
line wrap: on
line source
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;