XuqmGroup-Web/tenant-platform/src/router/index.ts

76 行
2.0 KiB
TypeScript

2026-04-21 22:07:29 +08:00
import { createRouter, createWebHistory } from 'vue-router'
import { useAuthStore } from '@/stores/auth'
const router = createRouter({
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: 'apps/:appId/im-config',
component: () => import('@/views/im/ImConfigView.vue'),
},
{
path: 'apps/:appId/im-webhooks',
component: () => import('@/views/im/ImWebhookView.vue'),
},
{
path: 'apps/:appId/im',
component: () => import('@/views/im/ImManagementView.vue'),
},
{
path: 'apps/:appId/update',
component: () => import('@/views/update/VersionManagementView.vue'),
},
2026-04-21 22:07:29 +08:00
{
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