Skip to content

Commit 27ebb6c

Browse files
Merge pull request #11 from kingscode/RouterWithGuardsAndchildRoutes
RouterWithGuardsAndchildRoutes
2 parents 2d1d884 + d2326e0 commit 27ebb6c

File tree

9 files changed

+88
-156
lines changed

9 files changed

+88
-156
lines changed

generator/index.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ module.exports = (api, options) => {
2626
...options,
2727
});
2828

29-
if (options.useTemplateLoader) {
30-
api.render('./templates/TemplateLoader', {
31-
...options,
32-
});
33-
}
3429
if (options.useAuthorisation) {
3530
api.render('./templates/Authorisation', {
3631
...options,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import Vue from 'vue';
2+
3+
export default function (to, from, next) {
4+
if (!Vue.prototype.$store.getters['Authorization/isLoggedIn']) {
5+
next({name: 'login'});
6+
return;
7+
}
8+
next();
9+
}
Lines changed: 4 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,17 @@
11
<template>
2-
<div id="app">
3-
<v-app id="inspire" v-if="$store.getters['Authorization/isLoggedIn']">
4-
<v-navigation-drawer
5-
app
6-
fixed
7-
v-model="menu"
8-
>
9-
<img :src="require('../assets/logo.png')" @click="$router.push({name: 'home'})" class="logo">
10-
<v-divider class="mt-10"/>
11-
<main-menu/>
12-
</v-navigation-drawer>
13-
<v-toolbar app color="primary" dark mfixed>
14-
<v-toolbar-side-icon @click.stop="menu = !menu"></v-toolbar-side-icon>
15-
<v-toolbar-title>Beheer</v-toolbar-title>
16-
<v-spacer/>
17-
<profile-menu></profile-menu>
18-
</v-toolbar>
19-
<v-content>
20-
<router-view/>
21-
</v-content>
22-
<v-footer app color="primary" inset>
23-
<span class="white--text pl-6">Created by Kings Code</span>
24-
</v-footer>
25-
</v-app>
2+
<div>
3+
<router-view></router-view>
264
</div>
275
</template>
286

297
<script>
30-
import ProfileMenu from './components/ProfileMenu.vue';
31-
import MainMenu from './components/MainMenu.vue';
328
339
export default {
34-
name: 'template-default',
35-
components: {ProfileMenu, MainMenu},
10+
name: 'app',
3611
data() {
3712
return {
38-
menu: true,
13+
3914
};
4015
},
41-
beforeCreate() {
42-
if (!this.$store.getters['Authorization/isLoggedIn']) {
43-
this.$router.push({name: 'login'});
44-
}
45-
},
4616
};
4717
</script>
48-
49-
<style scoped lang="scss">
50-
51-
.logo {
52-
display: block;
53-
margin: 30px auto;
54-
width: 50%;
55-
cursor: pointer;
56-
}
57-
</style>
58-
<style lang="scss">
59-
.v-dialog--fullscreen > .v-card.v-sheet.theme--light {
60-
background: rgb(248, 249, 250);
61-
}
62-
</style>

generator/templates/Default/src/newmain.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import './registerServiceWorker'
1414

1515
Vue.prototype.$http = API;
1616
window.$http = API;
17+
<%_ if (options.useAuthorisation) { _%>
18+
Vue.prototype.$store = store;
19+
<%_ } _%>
1720
<%_ if (options.useCrud) { _%>
1821
Vue.use(VuetifyResource);
1922
<%_ } _%>
Lines changed: 71 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import Vue from 'vue';
22
import Router from 'vue-router';
3+
<%_ if (options.useAuthorisation) { _%>
4+
import AuthorisationGuard from './guards/AuthorisationGuard';
5+
<%_ } _%>
36

47
Vue.use(Router);
58

@@ -8,77 +11,80 @@ export default new Router({
811
base: process.env.BASE_URL,
912
routes: [
1013
{
11-
path: '/',
12-
name: 'home',
13-
component: () => import('@/views/Home'),
14-
},
15-
{
16-
path: '/403',
17-
name: '403',
18-
component: () => import('./views/PageForbidden.vue'),
14+
path: '',
15+
redirect: {name: 'home'},
1916
},
2017
<%_ if (options.useAuthorisation) { _%>
2118
{
22-
path: '/login',
23-
name: 'login',
24-
component: () => import('@/views/Login'),
25-
<%_ if (options.useTemplateLoader) { _%>
26-
meta: {
27-
template: () => import('./templates/Authorisation.vue'),
28-
},
29-
<%_ } _%>
30-
},
31-
{
32-
path: '/password/forgotten',
33-
name: 'password.forgotten',
34-
component: () => import('./views/PasswordForgotten.vue'),
35-
<%_ if (options.useTemplateLoader) { _%>
36-
meta: {
37-
template: () => import('./templates/Authorisation.vue'),
38-
},
39-
<%_ } _%>
19+
path: '',
20+
component: () => import('@/templates/Authorisation'),
21+
children: [
22+
{
23+
path: '/login',
24+
name: 'login',
25+
component: () => import('@/views/Login'),
26+
},
27+
{
28+
path: '/password/forgotten',
29+
name: 'password.forgotten',
30+
component: () => import('./views/PasswordForgotten.vue'),
31+
},
32+
{
33+
path: '/password/reset/:token',
34+
name: 'password.reset',
35+
component: () => import('./views/PasswordReset.vue'),
36+
},
37+
{
38+
path: '/invitation/accept/:token',
39+
name: 'invitation.accept',
40+
component: () => import('./views/InvitationAccept.vue'),
41+
},
42+
]
4043
},
44+
<%_ } _%>
4145
{
42-
path: '/password/reset/:token',
43-
name: 'password.reset',
44-
component: () => import('./views/PasswordReset.vue'),
45-
<%_ if (options.useTemplateLoader) { _%>
46-
meta: {
47-
template: () => import('./templates/Authorisation.vue'),
48-
},
46+
path: '',
47+
<%_ if (options.useAuthorisation) { _%>
48+
beforeEnter: AuthorisationGuard,
4949
<%_ } _%>
50+
component: () => import('@/templates/Default'),
51+
children: [
52+
{
53+
path: '/',
54+
name: 'home',
55+
component: () => import('@/views/Home'),
56+
},
57+
<%_ if (options.useAuthorisation) { _%>
58+
{
59+
path: '/profile',
60+
name: 'profile',
61+
component: () => import('./views/Profile.vue')
62+
},
63+
<%_ } _%>
64+
<%_ if (options.useCrud) { _%>
65+
{
66+
path: '/users',
67+
name: 'users',
68+
component: () => import('./views/UserResource.vue')
69+
},
70+
<%_ } _%>
71+
{
72+
path: '/404',
73+
name: '404',
74+
component: () => import('./views/PageNotFound.vue'),
75+
},
76+
{
77+
path: '/403',
78+
name: '403',
79+
component: () => import('./views/PageForbidden.vue'),
80+
},
81+
{
82+
path: '*',
83+
redirect: '/404'
84+
},
85+
],
5086
},
51-
{
52-
path: '/invitation/accept/:token',
53-
name: 'invitation.accept',
54-
component: () => import('./views/InvitationAccept.vue'),
55-
<%_ if (options.useTemplateLoader) { _%>
56-
meta: {
57-
template: () => import('./templates/Authorisation.vue'),
58-
},
59-
<%_ } _%>
60-
},
61-
{
62-
path: '/profile',
63-
name: 'profile',
64-
component: () => import('./views/Profile.vue')
65-
},
66-
<%_ } _%>
67-
<%_ if (options.useCrud) { _%>
68-
{
69-
path: '/users',
70-
name: 'users',
71-
component: () => import('./views/UserResource.vue')
72-
},
73-
<%_ } _%>
74-
{
75-
path: '/404',
76-
name: '404',
77-
component: () => import('./views/PageNotFound.vue'),
78-
},
79-
{
80-
path: '*',
81-
redirect: '/404'
82-
},
87+
88+
8389
],
8490
});

generator/templates/TemplateLoader/src/App.vue

Lines changed: 0 additions & 30 deletions
This file was deleted.

prompts.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@ module.exports = [
99
message: 'Do you want to use a crud system?',
1010
default: true,
1111
},
12-
{
13-
name: 'useTemplateLoader',
14-
type: 'confirm',
15-
message: 'Do you want to use a template loader (multiple templates configuration in the router)',
16-
default: true,
17-
},
1812
{
1913
name: 'useAuthorisation',
2014
type: 'confirm',
@@ -39,4 +33,4 @@ module.exports = [
3933
message: 'What is the root API url? (you can change this later)',
4034
default: '//example.local/api',
4135
}
42-
];
36+
];

0 commit comments

Comments
 (0)