import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'; import { getFirebaseAuth } from '../utils/firebase'; const routes: RouteRecordRaw[] = [ { path: '/', component: () => import('../views/SiteLayout.vue'), children: [ { path: '', name: 'home', component: () => import('../components/site/SiteHome.vue') }, { path: 'dashboard', name: 'dashboard', component: () => import('../components/site/SiteDashboard.vue'), meta: { requiresAuth: true } }, { path: 'examples', name: 'examples', component: () => import('../components/site/SiteExamples.vue') }, { path: 'docs', name: 'docs', component: () => import('../components/site/SiteDocs.vue') }, { path: 'playground', name: 'playground', component: () => import('../components/site/SitePlayground.vue') }, { path: 'prompt-builder', name: 'prompt-builder', component: () => import('../components/site/SitePromptBuilder.vue') }, { path: 'api', name: 'api', component: () => import('../components/site/SiteApi.vue') } ] }, { path: '/studio/:id?', name: 'studio', component: () => import('../views/StudioView.vue'), meta: { requiresAuth: true } }, { path: '/deck/:id', name: 'deck', component: () => import('../views/DeckView.vue') } ]; const router = createRouter({ history: createWebHistory(import.meta.env.BASE_URL), routes, scrollBehavior(_to, _from, savedPosition) { if (savedPosition) { return savedPosition; } return { top: 0 }; } }); // Navigation Guard router.beforeEach(async (to, _from, next) => { const requiresAuth = to.matched.some(record => record.meta.requiresAuth); // Simple check - in a real app wait for auth init if (requiresAuth) { try { const auth = getFirebaseAuth(); if (!auth.currentUser) { // If not logged in, redirect home or show login // For now, we allow access but components might handle logic, // or we could redirect to home with a query param // next({ name: 'home' }); } } catch (e) { // Auth not initialized yet, proceed (components handle it) } } next(); }); export default router;