50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router';
|
|
import store from '../store';
|
|
|
|
const routes: Array<RouteRecordRaw> = [
|
|
{
|
|
path: '/login',
|
|
name: 'Login',
|
|
component: () => import('../views/Login/Login.vue'),
|
|
},
|
|
{
|
|
path: '/',
|
|
name: 'Main',
|
|
component: () => import('../views/Main/Main.vue'),
|
|
children: [
|
|
{
|
|
path: '/dashboard',
|
|
name: 'Dashboard',
|
|
component: () => import('../views/Main/Dashboard.vue'),
|
|
},
|
|
{
|
|
path: '/customer',
|
|
name: 'Customer',
|
|
component: () => import('../views/Customer/Main.vue'),
|
|
},
|
|
{
|
|
path: '/:pathMatch(.*)*',
|
|
name: 'NotFound',
|
|
component: () => import('../views/Main/NotFound.vue'),
|
|
},
|
|
],
|
|
},
|
|
];
|
|
|
|
const router = createRouter({
|
|
history: createWebHistory(process.env.BASE_URL),
|
|
routes,
|
|
});
|
|
|
|
router.beforeEach((to, from, next) => {
|
|
const loggedIn = store.getters.isLoggedIn;
|
|
|
|
if (to.name !== 'Login' && !loggedIn) {
|
|
next({ path: '/login', query: { redirect: to.fullPath } });
|
|
} else {
|
|
next();
|
|
}
|
|
});
|
|
|
|
export default router;
|