import { createRouter, createWebHistory } from 'vue-router' import { useStore } from '../stores' import HomeView from '../views/HomeView.vue' import NetView from '../views/NetView.vue' import AuthView from '../views/AuthView.vue' import SettingsView from '../views/SettingsView.vue' const router = createRouter({ history: createWebHistory(import.meta.env.BASE_URL), routes: [ { path: '/', name: 'home', component: HomeView, meta: { requiresAuth: true } }, { path: '/net', name: 'net', component: NetView, meta: { requiresAuth: true } }, { path: '/settings', name: 'settings', component: SettingsView, meta: { requiresAuth: true } }, { path: '/auth', name: 'auth', component: AuthView }, { path: '/:path(.*)', redirect: '/' } ] }) router.beforeEach((to) => { const store = useStore() if (to.meta.requiresAuth && !store.logged) return '/auth' if (to.name === 'auth' && store.logged) return '/' }) export default router