Skip to content

Commit

Permalink
Moved routes to a routes file.
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannestegner committed Nov 11, 2019
1 parent 12c0260 commit 5d752a0
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 23 deletions.
36 changes: 14 additions & 22 deletions src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ShowDown from 'vue-showdown';
// Internal imports.
import App from 'src/vue/App';
import Logger from 'src/js/Plugins/Logger';
import Routes from 'src/routes';

Vue.use(VueRouter);
Vue.use(Logger);
Expand All @@ -19,30 +20,21 @@ Vue.use(ShowDown, {
});

onLoad.then(() => {
const routerRoutes = [];
for (const route of Object.keys(Routes)) {
for (const lang of Object.keys(Routes[route])) {
routerRoutes.push({
name: route,
lang: lang,
path: Routes[route][lang].path,
component: () => Promise.resolve(import('src/vue/Pages/Page'))
});
}
}

const router = new VueRouter({
mode: 'history',
routes: [
{
path: '/',
// For code split we use a promise here to import dynamically.
component: () => Promise.resolve(import('src/vue/Pages/Page'))
},
{
path: '/om-sidan',
name: 'about',
component: () => Promise.resolve(import('src/vue/Pages/Page'))
},
{
path: '/social-säkerhet',
name: 'social-safety',
component: () => Promise.resolve(import('src/vue/Pages/Page'))
},
{
path: '/it-säkerhet',
name: 'it-security',
component: () => Promise.resolve(import('src/vue/Pages/Page'))
}
]
routes: routerRoutes
});

new Vue({
Expand Down
26 changes: 26 additions & 0 deletions src/routes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"home": {
"swe": {
"title": "Säker Online",
"path": "/"
}
},
"about": {
"swe": {
"title": "Om Säker Online",
"path": "/om-sidan"
}
},
"social-safety": {
"swe": {
"title": "Social Säkerhet",
"path": "/social-säkerhet"
}
},
"it-security": {
"swe": {
"title": "IT-Säkerhet",
"path": "/it-säkerhet"
}
}
}
2 changes: 1 addition & 1 deletion src/vue/Pages/Page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default Vue.component('Page', {
fetchData: function () {
this.content = null;
this.$logger.debug('Loading page: %s', this.$route.name);
fetch(`content/${this.$route.name ?? 'home'}/index.swe.md`)
fetch(`content/${this.$route.name ?? 'home'}/index.${this.lang}.md`)
.then(r => r.text())
.then(r => {
this.content = r;
Expand Down

0 comments on commit 5d752a0

Please sign in to comment.