mirror of
https://github.com/wangdage12/Snap.Server.Web.git
synced 2026-02-17 10:02:08 +08:00
修复路由问题
This commit is contained in:
7
src/components/RouterViewPlaceholder.vue
Normal file
7
src/components/RouterViewPlaceholder.vue
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<template>
|
||||||
|
<router-view></router-view>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
// 这是一个占位组件,用于嵌套路由
|
||||||
|
</script>
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
<!-- 有子路由 -->
|
<!-- 有子路由 -->
|
||||||
<el-sub-menu
|
<el-sub-menu
|
||||||
v-if="hasChildren(item)"
|
v-if="hasChildren(item)"
|
||||||
:index="item.path"
|
:index="getFullPath(item)"
|
||||||
>
|
>
|
||||||
<template #title>
|
<template #title>
|
||||||
<el-icon v-if="item.meta?.icon">
|
<el-icon v-if="item.meta?.icon">
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
<span>{{ item.meta?.title }}</span>
|
<span>{{ item.meta?.title }}</span>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<SidebarItem :routes="item.children!" :parent-path="item.path" />
|
<SidebarItem :routes="item.children!" :parent-path="getFullPath(item)" />
|
||||||
</el-sub-menu>
|
</el-sub-menu>
|
||||||
|
|
||||||
<!-- 普通菜单 -->
|
<!-- 普通菜单 -->
|
||||||
@@ -38,7 +38,7 @@ interface Props {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const props = withDefaults(defineProps<Props>(), {
|
const props = withDefaults(defineProps<Props>(), {
|
||||||
parentPath: ''
|
parentPath: '/dashboard'
|
||||||
})
|
})
|
||||||
|
|
||||||
const hasChildren = (route: RouteRecordRaw) =>
|
const hasChildren = (route: RouteRecordRaw) =>
|
||||||
@@ -50,6 +50,7 @@ const getFullPath = (route: RouteRecordRaw) => {
|
|||||||
return route.path
|
return route.path
|
||||||
}
|
}
|
||||||
// 否则拼接父级路径
|
// 否则拼接父级路径
|
||||||
return props.parentPath ? `/${props.parentPath}/${route.path}` : `/${route.path}`
|
const basePath = props.parentPath || ''
|
||||||
|
return basePath ? `${basePath}/${route.path}` : `/${route.path}`
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -95,9 +95,9 @@ const activeMenu = computed(() => route.path)
|
|||||||
* 获取菜单路由,直接使用配置的路由结构
|
* 获取菜单路由,直接使用配置的路由结构
|
||||||
*/
|
*/
|
||||||
const menuRoutes = computed(() => {
|
const menuRoutes = computed(() => {
|
||||||
// 直接返回路由配置中的子路由
|
// 查找 /dashboard 路由的子路由
|
||||||
const mainRoute = router.options.routes.find(r => r.path === '/')
|
const dashboardRoute = router.options.routes.find(r => r.path === '/dashboard')
|
||||||
return mainRoute?.children || []
|
return dashboardRoute?.children || []
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ const routes = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: 'system',
|
path: 'system',
|
||||||
|
component: () => import('@/components/RouterViewPlaceholder.vue'),
|
||||||
meta: { title: '系统管理', icon: 'Setting' },
|
meta: { title: '系统管理', icon: 'Setting' },
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ const handleLogin = async () => {
|
|||||||
await userStore.fetchUserInfo()
|
await userStore.fetchUserInfo()
|
||||||
|
|
||||||
ElMessage.success('登录成功')
|
ElMessage.success('登录成功')
|
||||||
router.push({ path: '/' })
|
router.push({ path: '/dashboard' })
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
ElMessage.error(error.message || '登录失败,请重试')
|
ElMessage.error(error.message || '登录失败,请重试')
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
Reference in New Issue
Block a user