Skip to content

Commit 2a3cff6

Browse files
committed
fix: Page jump 403 without permission
1 parent cd88d9d commit 2a3cff6

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

ui/src/router/common.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,38 @@ export const getPermissionRoute = (routes: Array<RouteRecordRaw>, to: RouteLocat
7171
)
7272
})
7373

74-
if (route?.name) {
74+
if (route?.name && route.name !== to.name) {
7575
return { name: route?.name, params: to.params }
7676
}
77+
78+
const globalRoute = findAccessibleRoute(routes)
79+
if (globalRoute && globalRoute.name !== to.name) {
80+
return { name: globalRoute.name, params: to.params}
81+
}
7782
return { name: 'noPermission' }
7883
}
84+
85+
86+
// 寻找有权限的路由
87+
88+
const findAccessibleRoute = (routes: Array<RouteRecordRaw>): RouteRecordRaw | null => {
89+
for (const route of routes) {
90+
const permission = route.meta?.permission
91+
if (permission && !hasPermission(permission as any, 'OR')) {
92+
continue
93+
}
94+
if (route.path.includes(':')) {
95+
continue
96+
}
97+
if (route.children && route.children.length > 0) {
98+
const child = findAccessibleRoute(route.children)
99+
if (child) return child
100+
}
101+
102+
if (!route.children || route.children.length === 0) {
103+
return route
104+
}
105+
}
106+
107+
return null
108+
}

0 commit comments

Comments
 (0)