0
0
Fork 0
salix-front-mindshore-fork2/src/router/index.ts

86 lines
2.4 KiB
TypeScript

import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router';
import { useSession } from '@/core/composables/useSession';
import i18n from '@/i18n';
const routes: Array<RouteRecordRaw> = [
{
path: '/login',
name: 'Login',
meta: { title: 'logIn' },
component: () => import('../views/Login/Login.vue'),
},
{
path: '/',
name: 'Main',
component: () => import('../views/Layout/Main.vue'),
redirect: { name: 'Dashboard' },
children: [
{
path: '/dashboard',
name: 'Dashboard',
meta: { title: 'dashboard' },
component: () => import('../views/Dashboard/Dashboard.vue'),
},
{
path: '/customer',
name: 'Customer',
meta: { title: 'customers' },
component: () => import('../views/Customer/Customer.vue'),
redirect: { name: 'List' },
children: [
{
path: 'list',
name: 'List',
meta: { title: 'customerList' },
component: () => import('../views/Customer/List.vue'),
},
{
path: ':id',
name: 'Card',
component: () => import('../views/Customer/Card/Card.vue'),
},
],
},
{
path: '/:pathMatch(.*)*',
name: 'NotFound',
component: () => import('../views/Layout/NotFound.vue'),
},
],
},
];
const router = createRouter({
history: createWebHistory(process.env.BASE_URL),
routes,
});
router.beforeEach((to, from, next) => {
const session = useSession();
const { isLoggedIn } = session;
if (!isLoggedIn && to.name !== 'Login') {
next({ path: '/login', query: { redirect: to.fullPath } });
} else {
next();
}
});
router.afterEach((to) => {
interface Meta {
title?: string;
}
const { t } = i18n.global;
const childMeta: Meta = to.meta;
if (childMeta && childMeta.title) {
//const parent = to.matched[1];
//const childTitle: string = childMeta.title;
document.title = t(`globals.pages.${childMeta.title}`);
}
});
export default router;