2026-04-21 22:07:29 +08:00
|
|
|
import { createRouter, createWebHistory } from 'vue-router'
|
|
|
|
|
import { useAuthStore } from '@/stores/auth'
|
|
|
|
|
|
|
|
|
|
const router = createRouter({
|
2026-04-24 10:42:11 +08:00
|
|
|
history: createWebHistory(import.meta.env.BASE_URL),
|
2026-04-21 22:07:29 +08:00
|
|
|
routes: [
|
|
|
|
|
{
|
|
|
|
|
path: '/login',
|
|
|
|
|
component: () => import('@/views/auth/LoginView.vue'),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: '/register',
|
|
|
|
|
component: () => import('@/views/auth/RegisterView.vue'),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: '/forgot-password',
|
|
|
|
|
component: () => import('@/views/auth/ForgotPasswordView.vue'),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: '/',
|
|
|
|
|
component: () => import('@/views/layout/MainLayout.vue'),
|
|
|
|
|
meta: { requiresAuth: true },
|
|
|
|
|
children: [
|
|
|
|
|
{
|
|
|
|
|
path: '',
|
|
|
|
|
redirect: '/dashboard',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: 'dashboard',
|
|
|
|
|
component: () => import('@/views/dashboard/DashboardView.vue'),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: 'apps',
|
|
|
|
|
component: () => import('@/views/apps/AppListView.vue'),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: 'apps/:id',
|
|
|
|
|
component: () => import('@/views/apps/AppDetailView.vue'),
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: 'accounts',
|
|
|
|
|
component: () => import('@/views/accounts/SubAccountView.vue'),
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
router.beforeEach((to) => {
|
|
|
|
|
const auth = useAuthStore()
|
|
|
|
|
if (to.meta.requiresAuth && !auth.token) {
|
|
|
|
|
return '/login'
|
|
|
|
|
}
|
|
|
|
|
if ((to.path === '/login' || to.path === '/register') && auth.token) {
|
|
|
|
|
return '/dashboard'
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export default router
|