File tree Expand file tree Collapse file tree 1 file changed +31
-1
lines changed
Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments