fix 路由相关问题

This commit is contained in:
Asoka 2025-06-05 09:58:45 +08:00
parent 87b8bd47dc
commit aaf85ccf22
6 changed files with 26 additions and 15 deletions

View File

@ -4,8 +4,10 @@
<Logo v-if="setIsShowLogo" />
<Breadcrumb />
</div>
<Horizontal :menuList="state.menuList" />
<div class="right-section">
<ModuleSwitch :menuList="state.menuList" />
<!-- <module-switch :menuList="state.menuList" /> -->
<User />
</div>
</div>
@ -21,7 +23,6 @@ import mittBus from '/@/utils/mitt'
import ModuleSwitch from './module-switch.vue'
//
const Breadcrumb = defineAsyncComponent(() => import('/@/layout/navBars/topBar/breadcrumb.vue'))
const User = defineAsyncComponent(() => import('/@/layout/navBars/topBar/user.vue'))
const Logo = defineAsyncComponent(() => import('/@/layout/logo/index.vue'))
const Horizontal = defineAsyncComponent(() => import('/@/layout/navMenu/horizontal.vue'))
@ -138,6 +139,7 @@ onBeforeMount(() => {
mittBus.emit('setSendClassicChildren', route.path)
}
})
</script>
<style scoped lang="scss">

View File

@ -2,7 +2,7 @@
<el-dropdown :show-timeout="70" :hide-timeout="50" trigger="click" @command="onMenuChange">
<div class="layout-navbars-breadcrumb-user-icon">
<i class="iconfont icon-diqiu" :title="$t('message.user.title1')"></i>
<span class="current-lang">{{ currentModuleName }}</span>
<span class="current-lang">{{ state.currentModuleName }}</span>
</div>
<template #dropdown>
<el-dropdown-menu>
@ -27,7 +27,6 @@ import { treeToList, listToTree, filterList } from '/@/utils/tree'
import { cloneDeep } from 'lodash-es'
import { useI18n } from 'vue-i18n'
const { t } = useI18n()
const router = useRouter()
//
@ -58,10 +57,6 @@ const menuLists = computed(() => {
return <RouteItems>props.menuList
})
const onMenuChange = (path: string) => {
console.log('path', path)
}
//
const filterRoutesFun = <T extends RouteItem>(arr: T[]): T[] => {
return arr
@ -108,13 +103,11 @@ const setSendClassicChildren = (path: string) => {
}
//
const setCurrentRouterHighlight = (currentRoute: RouteToFrom) => {
console.log('currentRoute', currentRoute)
const { path, meta } = currentRoute
if (themeConfig.value.layout === 'classic') {
let rootPath = getRootPath(path || '')
rootPath = rootPath || path || ''
setCurrentModuleName(`/${rootPath?.split('/')[1]}` || '')
state.defaultActive = `/${rootPath?.split('/')[1]}`
if (!state.defaultActive || state.defaultActive === '/') router.push(routesList.value[0].path)
} else {
@ -124,13 +117,30 @@ const setCurrentRouterHighlight = (currentRoute: RouteToFrom) => {
}
}
const onMenuChange = (path: string) => {
console.log('path', path)
let to = menuLists.value.find(item => item.path === path)
state.currentModuleName = t(to.meta?.title || '未命名模块')
setCurrentRouterHighlight(to)
let { layout } = themeConfig.value
if (layout === 'classic') {
mittBus.emit('setSendClassicChildren', setSendClassicChildren(to.path))
}
}
//
onBeforeMount(() => {
setCurrentRouterHighlight(route)
state.currentModuleName = t(route.meta?.title || '未命名模块')
let { layout } = themeConfig.value
if (layout === 'classic') {
mittBus.emit('setSendClassicChildren', setSendClassicChildren(route.path))
}
})
//
onBeforeRouteUpdate((to) => {
state.currentModuleName = t(to.meta?.title || '未命名模块')
// https://gitee.com/lyt-top/vue-next-admin/issues/I3YX6G
setCurrentRouterHighlight(to)
// tagsView

View File

@ -112,8 +112,7 @@ router.beforeEach(async (to, from, next) => {
Session.clear()
NProgress.done()
} else if (token && to.path === '/login') {
console.log('🔄 [路由守卫] 已登录用户访问登录页面,重定向到系统入口页面')
next('/system-entrance')
next('/')
NProgress.done()
} else {
const storesRoute = useRoute(pinia)

View File

@ -238,7 +238,7 @@ const signInSuccess = (isNoPower: boolean | undefined) => {
})
} else {
console.log('🚀 [登录成功] 无redirect参数或redirect是首页跳转到系统入口页面: /system-entrance')
router.push('/system-entrance')
router.push('/')
}
//
const signInText = t('message.signInText')

View File

@ -143,7 +143,7 @@ const signInSuccess = (isNoPower: boolean | undefined) => {
query: Object.keys(<string>route.query?.params).length > 0 ? JSON.parse(<string>route.query?.params) : '',
})
} else {
router.push('/system-entrance')
router.push('/')
}
//
const signInText = t('message.signInText')

View File

@ -128,7 +128,7 @@ const signInSuccess = (isNoPower: boolean | undefined) => {
query: Object.keys(<string>route.query?.params).length > 0 ? JSON.parse(<string>route.query?.params) : '',
})
} else {
router.push('/system-entrance')
router.push('/')
}
//
const signInText = t('message.signInText')