112 lines
No EOL
3.3 KiB
TypeScript
112 lines
No EOL
3.3 KiB
TypeScript
import {createRouter, createWebHashHistory, createWebHistory, type RouteRecordRaw} from "vue-router";
|
|
import {useAuthStore} from "@/stores/auth.store.ts";
|
|
import {useShowTypeStore} from '@/stores/showType.store';
|
|
|
|
const routes: Array<RouteRecordRaw> = [
|
|
{
|
|
path: '/',
|
|
name: 'Backoffice',
|
|
component: () => import('../pages/Backoffice.vue'),
|
|
children: [
|
|
{
|
|
path: '',
|
|
name: 'Dashboard',
|
|
component: () => import('@/components/content/Dashboard.vue')
|
|
},
|
|
{
|
|
path: 'show',
|
|
name: 'Trasmissioni',
|
|
component: () => import('@/components/content/Show.vue'),
|
|
meta: {showType: 'shows'}
|
|
},
|
|
{
|
|
path: 'archive',
|
|
name: 'Archivio',
|
|
component: () => import('@/components/content/Archive.vue')},
|
|
{
|
|
path: 'playlist',
|
|
name: 'Playlist',
|
|
component: () => import('@/components/content/Playlist.vue'),
|
|
meta: {showType: 'shows'}
|
|
},
|
|
{
|
|
path: 'blocks',
|
|
name: 'Blocchi dinamici',
|
|
component: () => import('@/components/content/SmartBlock.vue'),
|
|
meta: {showType: 'shows'}
|
|
},
|
|
{
|
|
path: 'podcast',
|
|
name: 'Podcast',
|
|
component: () => import('@/components/content/Podcast.vue')
|
|
},
|
|
{
|
|
path: 'webstream',
|
|
name: 'Webstream',
|
|
component: () => import('@/components/content/Webstream.vue')
|
|
},
|
|
{
|
|
path: 'spot',
|
|
name: 'Spot',
|
|
component: () => import('@/components/content/Show.vue'),
|
|
meta: {showType: 'spots'}
|
|
},
|
|
{
|
|
path: 'spot-playlist',
|
|
name: 'Spot playlist',
|
|
component: () => import('@/components/content/Playlist.vue'),
|
|
meta: {showType: 'spots'}
|
|
},
|
|
{
|
|
path: 'spot-blocks',
|
|
name: 'Spot Blocchi dinamici',
|
|
component: () => import('@/components/content/SmartBlock.vue'),
|
|
meta: {showType: 'spots'}
|
|
},
|
|
{
|
|
path: 'user-profile',
|
|
name: 'UserProfile',
|
|
component: () => import('@/components/content/UserProfile.vue')
|
|
},
|
|
]
|
|
},
|
|
{
|
|
path: '/login',
|
|
name: 'Login',
|
|
component: () => import('../pages/Login.vue'),
|
|
},
|
|
];
|
|
|
|
const router = createRouter({
|
|
history: createWebHashHistory(),
|
|
routes
|
|
});
|
|
|
|
/**
|
|
* Navigation Guards
|
|
*/
|
|
router.beforeEach(async (to, from, next) => {
|
|
const publicPages = ['/login'];
|
|
const authRequired = !publicPages.includes(to.path);
|
|
const auth = useAuthStore();
|
|
|
|
if (authRequired && !auth.userData.login) {
|
|
return next('/login');
|
|
}
|
|
|
|
const showTypeStore = useShowTypeStore();
|
|
switch (to.meta.showType) {
|
|
case 'shows':
|
|
showTypeStore.setAsShows();
|
|
break;
|
|
case 'spots':
|
|
showTypeStore.setAsSpots();
|
|
break;
|
|
default:
|
|
showTypeStore.clearType();
|
|
}
|
|
|
|
next();
|
|
});
|
|
|
|
export default router; |