2019-09-01 14:38:13 +02:00
|
|
|
import Vue from 'vue';
|
|
|
|
import Router from 'vue-router';
|
2019-07-19 16:07:26 +02:00
|
|
|
|
2021-06-14 21:44:07 +02:00
|
|
|
import Home from '@/views/Home.vue';
|
|
|
|
import Login from '@/views/Login.vue';
|
2021-06-15 15:22:22 +02:00
|
|
|
import Workspace from '@/views/Workspace.vue';
|
2021-07-21 18:12:42 +02:00
|
|
|
import Minimal from '@/views/Minimal.vue';
|
2021-06-21 14:07:49 +02:00
|
|
|
import DownloadConfig from '@/views/DownloadConfig.vue';
|
2021-06-14 21:44:07 +02:00
|
|
|
import { isLoggedIn } from '@/utils/Auth';
|
2021-07-04 10:04:21 +02:00
|
|
|
import { config } from '@/utils/ConfigHelpers';
|
2021-06-15 15:22:22 +02:00
|
|
|
import { metaTagData } from '@/utils/defaults';
|
2021-05-17 19:53:35 +02:00
|
|
|
|
2021-06-14 21:44:07 +02:00
|
|
|
Vue.use(Router);
|
2021-06-13 10:40:40 +02:00
|
|
|
|
2021-08-01 16:25:24 +02:00
|
|
|
/**
|
|
|
|
* Checks if the current user is either authenticated,
|
|
|
|
* or if authentication is not enabled
|
|
|
|
* @returns true if user logged in, or user management not enabled
|
|
|
|
*/
|
2021-06-13 10:40:40 +02:00
|
|
|
const isAuthenticated = () => {
|
2021-07-04 10:04:21 +02:00
|
|
|
const users = config.appConfig.auth;
|
2021-08-01 16:25:24 +02:00
|
|
|
return (!users || users.length === 0 || isLoggedIn(users));
|
2021-06-13 10:40:40 +02:00
|
|
|
};
|
|
|
|
|
2021-04-03 10:08:28 +02:00
|
|
|
const router = new Router({
|
2019-07-19 16:07:26 +02:00
|
|
|
routes: [
|
|
|
|
{
|
|
|
|
path: '/',
|
|
|
|
name: 'home',
|
2019-09-01 14:38:13 +02:00
|
|
|
component: Home,
|
2021-07-04 10:04:21 +02:00
|
|
|
props: config,
|
2021-04-03 10:08:28 +02:00
|
|
|
meta: {
|
2021-07-04 10:04:21 +02:00
|
|
|
title: config.pageInfo.title || 'Home Page',
|
2021-06-15 15:22:22 +02:00
|
|
|
metaTags: metaTagData,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '/workspace',
|
|
|
|
name: 'workspace',
|
|
|
|
component: Workspace,
|
2021-07-04 10:04:21 +02:00
|
|
|
props: config,
|
2021-06-15 15:22:22 +02:00
|
|
|
meta: {
|
2021-07-04 10:04:21 +02:00
|
|
|
title: config.pageInfo.title || 'Dashy Workspace',
|
2021-06-15 15:22:22 +02:00
|
|
|
metaTags: metaTagData,
|
2021-04-03 10:08:28 +02:00
|
|
|
},
|
2019-07-19 16:07:26 +02:00
|
|
|
},
|
2021-07-21 18:12:42 +02:00
|
|
|
{
|
|
|
|
path: '/minimal',
|
|
|
|
name: 'minimal',
|
|
|
|
component: Minimal,
|
|
|
|
props: config,
|
|
|
|
meta: {
|
|
|
|
title: config.pageInfo.title || 'Dashy Start Page',
|
|
|
|
metaTags: metaTagData,
|
|
|
|
},
|
|
|
|
},
|
2021-06-13 10:40:40 +02:00
|
|
|
{
|
|
|
|
path: '/login',
|
|
|
|
name: 'login',
|
|
|
|
component: Login,
|
|
|
|
props: {
|
2021-07-04 10:04:21 +02:00
|
|
|
appConfig: config.appConfig,
|
2021-06-13 10:40:40 +02:00
|
|
|
},
|
|
|
|
beforeEnter: (to, from, next) => {
|
|
|
|
if (isAuthenticated()) router.push({ path: '/' });
|
|
|
|
next();
|
|
|
|
},
|
|
|
|
},
|
2019-07-19 16:07:26 +02:00
|
|
|
{
|
|
|
|
path: '/about',
|
|
|
|
name: 'about',
|
2019-09-01 14:38:13 +02:00
|
|
|
component: () => import(/* webpackChunkName: "about" */ './views/About.vue'),
|
|
|
|
},
|
2021-06-21 14:07:49 +02:00
|
|
|
{
|
|
|
|
path: '/download',
|
|
|
|
name: 'download',
|
|
|
|
component: DownloadConfig,
|
2021-07-04 10:04:21 +02:00
|
|
|
props: config,
|
2021-06-21 14:07:49 +02:00
|
|
|
meta: {
|
2021-07-04 10:04:21 +02:00
|
|
|
title: config.pageInfo.title || 'Download Dashy Config',
|
2021-06-21 14:07:49 +02:00
|
|
|
metaTags: metaTagData,
|
|
|
|
},
|
|
|
|
},
|
2019-09-01 14:38:13 +02:00
|
|
|
],
|
|
|
|
});
|
2021-04-03 10:08:28 +02:00
|
|
|
|
2021-06-13 10:40:40 +02:00
|
|
|
router.beforeEach((to, from, next) => {
|
|
|
|
if (to.name !== 'login' && !isAuthenticated()) next({ name: 'login' });
|
|
|
|
else next();
|
|
|
|
});
|
|
|
|
|
|
|
|
const defaultTitle = 'Dashy';
|
2021-04-03 10:08:28 +02:00
|
|
|
router.afterEach((to) => {
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
document.title = to.meta.title || defaultTitle;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
export default router;
|