mirror of
https://github.com/memohai/Memoh.git
synced 2026-04-27 07:16:19 +09:00
refactor(web): router
This commit is contained in:
@@ -72,7 +72,7 @@ const route = useRoute()
|
||||
const { t } = i18n.global
|
||||
const curSlider = ref()
|
||||
const curSelectSlide = (cur: string) => computed(() => {
|
||||
return curSlider.value === cur || new RegExp(`^/main/${cur}$`).test(route.path)
|
||||
return curSlider.value === cur || new RegExp(`^/${cur}$`).test(route.path)
|
||||
})
|
||||
const sidebarInfo = computed(() => [
|
||||
{
|
||||
|
||||
@@ -141,7 +141,7 @@ const login = form.handleSubmit(async (values) => {
|
||||
} else {
|
||||
throw new Error(t('auth.loginFailed'))
|
||||
}
|
||||
router.replace({ name: 'Main' })
|
||||
router.replace({ path: '/chat' })
|
||||
} catch {
|
||||
toast.error(t('auth.invalidCredentials'), {
|
||||
description: t('auth.retryHint'),
|
||||
|
||||
+85
-82
@@ -1,4 +1,8 @@
|
||||
import { createRouter, createWebHistory, type RouteLocationNormalized } from 'vue-router'
|
||||
import {
|
||||
createRouter,
|
||||
createWebHistory,
|
||||
type RouteLocationNormalized,
|
||||
} from 'vue-router'
|
||||
import { h } from 'vue'
|
||||
import { RouterView } from 'vue-router'
|
||||
import { i18nRef } from './i18n'
|
||||
@@ -6,102 +10,101 @@ import { i18nRef } from './i18n'
|
||||
const routes = [
|
||||
{
|
||||
path: '/',
|
||||
redirect: '/login'
|
||||
redirect: '/login',
|
||||
component: () => import('@/pages/main-section/index.vue'),
|
||||
children: [
|
||||
{
|
||||
name: 'chat',
|
||||
path: '/chat',
|
||||
component: () => import('@/pages/chat/index.vue'),
|
||||
meta: {
|
||||
breadcrumb: i18nRef('sidebar.chat'),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'home',
|
||||
path: '/home',
|
||||
component: () => import('@/pages/home/index.vue'),
|
||||
meta: {
|
||||
breadcrumb: i18nRef('home.title'),
|
||||
},
|
||||
},
|
||||
{
|
||||
path: '/bots',
|
||||
component: { render: () => h(RouterView) },
|
||||
meta: {
|
||||
breadcrumb: i18nRef('sidebar.bots'),
|
||||
},
|
||||
children: [
|
||||
{
|
||||
name: 'bots',
|
||||
path: '',
|
||||
component: () => import('@/pages/bots/index.vue'),
|
||||
},
|
||||
{
|
||||
name: 'bot-detail',
|
||||
path: ':botId',
|
||||
component: () => import('@/pages/bots/detail.vue'),
|
||||
meta: {
|
||||
breadcrumb: (route: RouteLocationNormalized) => route.params.botId,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'models',
|
||||
path: '/models',
|
||||
component: () => import('@/pages/models/index.vue'),
|
||||
meta: {
|
||||
breadcrumb: i18nRef('sidebar.models'),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'settings',
|
||||
path: '/settings',
|
||||
component: () => import('@/pages/settings/index.vue'),
|
||||
meta: {
|
||||
breadcrumb: i18nRef('sidebar.settings'),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'mcp',
|
||||
path: '/mcp',
|
||||
component: () => import('@/pages/mcp/index.vue'),
|
||||
meta: {
|
||||
breadcrumb: 'MCP',
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'platform',
|
||||
path: '/platform',
|
||||
component: () => import('@/pages/platform/index.vue'),
|
||||
meta: {
|
||||
breadcrumb: i18nRef('sidebar.platform'),
|
||||
},
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
name: 'Login',
|
||||
path: '/login',
|
||||
component: () => import('@/pages/login/index.vue')
|
||||
}, {
|
||||
name: 'Main',
|
||||
component: () => import('@/pages/main-section/index.vue'),
|
||||
path: '/main',
|
||||
redirect: '/main/chat',
|
||||
meta: {
|
||||
breadcrumb: i18nRef('breadcrumb.main')
|
||||
|
||||
},
|
||||
children: [{
|
||||
name: 'chat',
|
||||
path: 'chat',
|
||||
component: () => import('@/pages/chat/index.vue'),
|
||||
meta: {
|
||||
breadcrumb: i18nRef('sidebar.chat')
|
||||
}
|
||||
}, {
|
||||
name: 'home',
|
||||
path: 'home',
|
||||
component: () => import('@/pages/home/index.vue'),
|
||||
meta: {
|
||||
breadcrumb: i18nRef('home.title')
|
||||
}
|
||||
}, {
|
||||
path: 'bots',
|
||||
component: { render: () => h(RouterView) },
|
||||
meta: {
|
||||
breadcrumb: i18nRef('sidebar.bots')
|
||||
},
|
||||
children: [
|
||||
{
|
||||
name: 'bots',
|
||||
path: '',
|
||||
component: () => import('@/pages/bots/index.vue'),
|
||||
},
|
||||
{
|
||||
name: 'bot-detail',
|
||||
path: ':botId',
|
||||
component: () => import('@/pages/bots/detail.vue'),
|
||||
meta: {
|
||||
breadcrumb: (route: RouteLocationNormalized) => route.params.botId,
|
||||
},
|
||||
},
|
||||
],
|
||||
}, {
|
||||
name: 'models',
|
||||
path: 'models',
|
||||
component: () => import('@/pages/models/index.vue'),
|
||||
meta: {
|
||||
breadcrumb: i18nRef('sidebar.models')
|
||||
}
|
||||
}, {
|
||||
name: 'settings',
|
||||
path: 'settings',
|
||||
component: () => import('@/pages/settings/index.vue'),
|
||||
meta: {
|
||||
breadcrumb: i18nRef('sidebar.settings')
|
||||
}
|
||||
}, {
|
||||
name: 'mcp',
|
||||
path: 'mcp',
|
||||
component: () => import('@/pages/mcp/index.vue'),
|
||||
meta: {
|
||||
breadcrumb: 'MCP'
|
||||
}
|
||||
}, {
|
||||
name: 'platform',
|
||||
path: 'platform',
|
||||
component: () => import('@/pages/platform/index.vue'),
|
||||
meta: {
|
||||
breadcrumb: i18nRef('sidebar.platform')
|
||||
}
|
||||
}]
|
||||
}
|
||||
|
||||
component: () => import('@/pages/login/index.vue'),
|
||||
},
|
||||
|
||||
]
|
||||
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes,
|
||||
})
|
||||
router.beforeEach((to) => {
|
||||
const token = localStorage.getItem('token')
|
||||
|
||||
|
||||
if (to.fullPath !== '/login') {
|
||||
return token ? true : { name: 'Login' }
|
||||
} else {
|
||||
return token ? { path:'Main' } : true
|
||||
return token ? { path: '/chat' } : true
|
||||
}
|
||||
})
|
||||
|
||||
export default router
|
||||
export default router
|
||||
|
||||
Reference in New Issue
Block a user