This commit is contained in:
@@ -3,6 +3,10 @@ import { createRouter, createWebHistory } from 'vue-router';
|
||||
import CatalogPage from '@/pages/CatalogPage.vue';
|
||||
import ListingDetailPage from '@/pages/ListingDetailPage.vue';
|
||||
import ProductDetailPage from '@/pages/ProductDetailPage.vue';
|
||||
import AdminHomePage from '@/pages/AdminHomePage.vue';
|
||||
import AdminShell from '@/pages/AdminShell.vue';
|
||||
import LoginPage from '@/pages/LoginPage.vue';
|
||||
import { useAuth } from '@/composables/useAuth.js';
|
||||
import AdminImagePage from '@/pages/AdminImagePage.vue';
|
||||
|
||||
export default createRouter({
|
||||
@@ -11,6 +15,21 @@ export default createRouter({
|
||||
{ path: '/', name: 'catalog', component: CatalogPage },
|
||||
{ path: '/listings/:id', name: 'listing-detail', component: ListingDetailPage },
|
||||
{ path: '/products/:slug', name: 'product-detail', component: ProductDetailPage },
|
||||
{ path: '/admin/inventory/:id/images', name: 'admin-image-manager', component: AdminImagePage },
|
||||
{ path: '/login', name: 'login', component: LoginPage },
|
||||
{
|
||||
path: '/admin',
|
||||
component: AdminShell,
|
||||
children: [
|
||||
{ path: '', name: 'admin-home', component: AdminHomePage },
|
||||
{ path: 'inventory/:id/images', name: 'admin-image-manager', component: AdminImagePage },
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const auth = useAuth();
|
||||
router.beforeEach(async (to) => {
|
||||
if (!to.path.startsWith('/admin')) return true;
|
||||
if (!auth.isAuthenticated.value) await auth.load();
|
||||
return auth.isAuthenticated.value ? true : { name: 'login' };
|
||||
});
|
||||
Reference in New Issue
Block a user