Mercurial > gemma
comparison 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 |
comparison
equal
deleted
inserted
replaced
12:000adddf74c8 | 13:88d0d60924cf |
---|---|
1 import Vue from "vue"; | |
2 import Router from "vue-router"; | |
3 import Login from "./views/Login.vue"; | |
4 import Main from "./views/Main.vue"; | |
5 import store from "./store"; | |
6 | |
7 Vue.use(Router); | |
8 | |
9 const router = new Router({ | |
10 routes: [ | |
11 { | |
12 path: "/login", | |
13 name: "login", | |
14 component: Login | |
15 }, | |
16 { | |
17 path: "/", | |
18 name: "main", | |
19 component: Main, | |
20 meta: { | |
21 requiresAuth: true | |
22 } | |
23 }, | |
24 { | |
25 path: "*", | |
26 component: Login | |
27 } | |
28 ] | |
29 }); | |
30 | |
31 router.beforeEach((to, from, next) => { | |
32 const requiresAuth = to.matched.some(record => record.meta.requiresAuth); | |
33 const currentUser = store.getters["user/authenticated"]; | |
34 if (requiresAuth && !currentUser) { | |
35 next("/login"); | |
36 } else if (requiresAuth && currentUser) { | |
37 next(); | |
38 } else { | |
39 next(); | |
40 } | |
41 }); | |
42 | |
43 export default router; |