diff --git a/src/components/RouterViewPlaceholder.vue b/src/components/RouterViewPlaceholder.vue new file mode 100644 index 0000000..f1d95e6 --- /dev/null +++ b/src/components/RouterViewPlaceholder.vue @@ -0,0 +1,7 @@ + + + \ No newline at end of file diff --git a/src/components/SidebarItem.vue b/src/components/SidebarItem.vue index 0f623a2..69eb54d 100644 --- a/src/components/SidebarItem.vue +++ b/src/components/SidebarItem.vue @@ -3,7 +3,7 @@ - + @@ -38,7 +38,7 @@ interface Props { } const props = withDefaults(defineProps(), { - parentPath: '' + parentPath: '/dashboard' }) const hasChildren = (route: RouteRecordRaw) => @@ -50,6 +50,7 @@ const getFullPath = (route: RouteRecordRaw) => { return route.path } // 否则拼接父级路径 - return props.parentPath ? `/${props.parentPath}/${route.path}` : `/${route.path}` + const basePath = props.parentPath || '' + return basePath ? `${basePath}/${route.path}` : `/${route.path}` } diff --git a/src/layouts/DefaultLayout.vue b/src/layouts/DefaultLayout.vue index 4837518..320bdc2 100644 --- a/src/layouts/DefaultLayout.vue +++ b/src/layouts/DefaultLayout.vue @@ -95,9 +95,9 @@ const activeMenu = computed(() => route.path) * 获取菜单路由,直接使用配置的路由结构 */ const menuRoutes = computed(() => { - // 直接返回路由配置中的子路由 - const mainRoute = router.options.routes.find(r => r.path === '/') - return mainRoute?.children || [] + // 查找 /dashboard 路由的子路由 + const dashboardRoute = router.options.routes.find(r => r.path === '/dashboard') + return dashboardRoute?.children || [] }) diff --git a/src/router/index.ts b/src/router/index.ts index fd45c33..b60a1eb 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -29,6 +29,7 @@ const routes = [ }, { path: 'system', + component: () => import('@/components/RouterViewPlaceholder.vue'), meta: { title: '系统管理', icon: 'Setting' }, children: [ { diff --git a/src/views/login/index.vue b/src/views/login/index.vue index 082733f..8f52ba0 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -101,7 +101,7 @@ const handleLogin = async () => { await userStore.fetchUserInfo() ElMessage.success('登录成功') - router.push({ path: '/' }) + router.push({ path: '/dashboard' }) } catch (error: any) { ElMessage.error(error.message || '登录失败,请重试') } finally {