Show loader when route changes

This commit is contained in:
Alicia Sykes 2021-09-19 21:18:41 +01:00
parent cf5f7234eb
commit 0927ea879b

View File

@ -7,6 +7,7 @@
// Import Vue.js and vue router // Import Vue.js and vue router
import Vue from 'vue'; import Vue from 'vue';
import Router from 'vue-router'; import Router from 'vue-router';
import ProgressBar from 'rsup-progress';
// Import views // Import views
import Home from '@/views/Home.vue'; import Home from '@/views/Home.vue';
@ -21,6 +22,7 @@ import { config } from '@/utils/ConfigHelpers';
import { metaTagData, startingView, routePaths } from '@/utils/defaults'; import { metaTagData, startingView, routePaths } from '@/utils/defaults';
Vue.use(Router); Vue.use(Router);
const progress = new ProgressBar({ color: 'var(--progress-bar)' });
/* Returns true if user is already authenticated, or if auth is not enabled */ /* Returns true if user is already authenticated, or if auth is not enabled */
const isAuthenticated = () => { const isAuthenticated = () => {
@ -119,12 +121,14 @@ const router = new Router({
* If not logged in, prevent all access and redirect them to login page * If not logged in, prevent all access and redirect them to login page
* */ * */
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
progress.start();
if (to.name !== 'login' && !isAuthenticated()) next({ name: 'login' }); if (to.name !== 'login' && !isAuthenticated()) next({ name: 'login' });
else next(); else next();
}); });
/* If title is missing, then apply default page title */ /* If title is missing, then apply default page title */
router.afterEach((to) => { router.afterEach((to) => {
progress.end();
Vue.nextTick(() => { Vue.nextTick(() => {
document.title = to.meta.title || 'Dashy'; document.title = to.meta.title || 'Dashy';
}); });