init
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
import { createRouter, createWebHistory } from 'vue-router';
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
import { ROUTE_NAMES } from '@/consts/routeNames';
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(import.meta.env.BASE_URL),
|
||||
routes: [
|
||||
{
|
||||
path: '/login',
|
||||
name: ROUTE_NAMES.Login,
|
||||
component: () => import('../views/CmsLoginView.vue'),
|
||||
meta: { title: 'CMS - Sign in', hideNav: true }
|
||||
},
|
||||
{
|
||||
path: '/products/:id',
|
||||
name: ROUTE_NAMES.ProductDetail,
|
||||
component: () => import('../views/CmsProductDetailView.vue'),
|
||||
meta: { requiresAuth: true, title: 'CMS - Product', activeMenu: '/products' }
|
||||
},
|
||||
{
|
||||
path: '/products/:productId/variants/:variantId',
|
||||
name: ROUTE_NAMES.ProductVariantDetail,
|
||||
component: () => import('../views/CmsProductVariantDetailView.vue'),
|
||||
meta: { requiresAuth: true, title: 'CMS - Variant', activeMenu: '/products' }
|
||||
},
|
||||
{
|
||||
path: '/products',
|
||||
name: ROUTE_NAMES.Products,
|
||||
component: () => import('../views/CmsProductsView.vue'),
|
||||
meta: { requiresAuth: true, title: 'CMS - Products' }
|
||||
},
|
||||
{
|
||||
path: '/categories',
|
||||
name: ROUTE_NAMES.Categories,
|
||||
component: () => import('../views/CmsCategoriesView.vue'),
|
||||
meta: { requiresAuth: true, title: 'CMS - Categories' }
|
||||
},
|
||||
{
|
||||
path: '/discount-codes',
|
||||
name: ROUTE_NAMES.DiscountCodes,
|
||||
component: () => import('../views/CmsDiscountCodesView.vue'),
|
||||
meta: { requiresAuth: true, title: 'CMS - Discount codes' }
|
||||
},
|
||||
{
|
||||
path: '/orders/:id',
|
||||
name: ROUTE_NAMES.OrderDetail,
|
||||
component: () => import('../views/CmsOrderDetailView.vue'),
|
||||
meta: { requiresAuth: true, title: 'CMS - Order', activeMenu: '/orders' }
|
||||
},
|
||||
{
|
||||
path: '/orders',
|
||||
name: ROUTE_NAMES.Orders,
|
||||
component: () => import('../views/CmsOrdersView.vue'),
|
||||
meta: { requiresAuth: true, title: 'CMS - Orders' }
|
||||
},
|
||||
{
|
||||
path: '/settings',
|
||||
component: () => import('../views/CmsSettingsLayout.vue'),
|
||||
meta: { requiresAuth: true, title: 'CMS - Settings', activeMenu: '/settings' },
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
name: ROUTE_NAMES.ShopSettings,
|
||||
component: () => import('../views/CmsShopSettingsView.vue'),
|
||||
meta: { requiresAuth: true, title: 'CMS - Shop settings', activeMenu: '/settings' }
|
||||
},
|
||||
{
|
||||
path: 'notifications',
|
||||
name: ROUTE_NAMES.Notifications,
|
||||
component: () => import('../views/CmsNotificationsView.vue'),
|
||||
meta: { requiresAuth: true, title: 'CMS - Notifications', activeMenu: '/settings' }
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
path: '/wallet',
|
||||
name: ROUTE_NAMES.Wallet,
|
||||
component: () => import('../views/CmsWalletView.vue'),
|
||||
meta: { requiresAuth: true, title: 'CMS - Wallet' }
|
||||
},
|
||||
{
|
||||
path: '/:pathMatch(.*)*',
|
||||
redirect: { name: ROUTE_NAMES.Login }
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
router.beforeEach(to => {
|
||||
const auth = useAuthStore();
|
||||
|
||||
if (to.meta.requiresAuth && !auth.isSignedIn) {
|
||||
return { name: ROUTE_NAMES.Login };
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
router.afterEach(to => {
|
||||
const title = to.meta.title;
|
||||
|
||||
if (title && typeof title === 'string') {
|
||||
document.title = title;
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
Reference in New Issue
Block a user