Skip to content

Commit e70f966

Browse files
remove templateloader
add child routes add route guards
1 parent 2d1d884 commit e70f966

9 files changed

Lines changed: 78 additions & 155 deletions

File tree

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+
}

generator/templates/TemplateLoader/src/templates/Authorisation.vue renamed to generator/templates/Authorisation/src/templates/Authorisation.vue

File renamed without changes.
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
<%_ } _%>

generator/templates/Default/src/router.js

Lines changed: 61 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -12,73 +12,70 @@ export default new Router({
1212
name: 'home',
1313
component: () => import('@/views/Home'),
1414
},
15+
// <%_ if (options.useAuthorisation) { _%>
1516
{
16-
path: '/403',
17-
name: '403',
18-
component: () => import('./views/PageForbidden.vue'),
17+
path: '',
18+
component: () => import('@/templates/Authorisation'),
19+
children: [
20+
{
21+
path: '/login',
22+
name: 'login',
23+
component: () => import('@/views/Login'),
24+
},
25+
{
26+
path: '/password/forgotten',
27+
name: 'password.forgotten',
28+
component: () => import('./views/PasswordForgotten.vue'),
29+
},
30+
{
31+
path: '/password/reset/:token',
32+
name: 'password.reset',
33+
component: () => import('./views/PasswordReset.vue'),
34+
},
35+
{
36+
path: '/invitation/accept/:token',
37+
name: 'invitation.accept',
38+
component: () => import('./views/InvitationAccept.vue'),
39+
},
40+
]
1941
},
20-
<%_ if (options.useAuthorisation) { _%>
42+
// <%_ } _%>
2143
{
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-
<%_ } _%>
40-
},
41-
{
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-
},
49-
<%_ } _%>
50-
},
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'
44+
path: '',
45+
beforeEnter: AuthorisationGuard,
46+
component: () => import('@/templates/Default'),
47+
children: [
48+
// <%_ if (options.useAuthorisation) { _%>
49+
{
50+
path: '/profile',
51+
name: 'profile',
52+
component: () => import('./views/Profile.vue')
53+
},
54+
// <%_ } _%>
55+
// <%_ if (options.useCrud) { _%>
56+
{
57+
path: '/users',
58+
name: 'users',
59+
component: () => import('./views/UserResource.vue')
60+
},
61+
// <%_ } _%>
62+
{
63+
path: '/404',
64+
name: '404',
65+
component: () => import('./views/PageNotFound.vue'),
66+
},
67+
{
68+
path: '/403',
69+
name: '403',
70+
component: () => import('./views/PageForbidden.vue'),
71+
},
72+
{
73+
path: '*',
74+
redirect: '/404'
75+
},
76+
],
8277
},
78+
79+
8380
],
8481
});

generator/templates/TemplateLoader/src/templates/Default.vue renamed to generator/templates/Default/src/templates/Default.vue

File renamed without changes.

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)