Optimize route

This commit is contained in:
2024-01-24 16:09:16 +08:00
parent 7ad480e23a
commit 983d8e0923
5 changed files with 29 additions and 14 deletions

View File

@@ -1,5 +1,4 @@
import { RouteObject } from 'react-router'
import { hasPathPermission } from '@/util/auth'
import { hasPathPermission, hasPermission } from '@/util/auth'
export const getRedirectUrl = (path: string, redirectUrl: string): string => {
return `${path}?redirect=${encodeURIComponent(redirectUrl)}`
@@ -18,12 +17,13 @@ export const getAuthRoute = (
route: RouteJsonObject[],
parentPermission: boolean = false
): RouteJsonObject[] => {
return route
const temp = route
.filter(
(value) =>
value.path === '*' ||
!(value.permission || parentPermission) ||
hasPathPermission(value.absolutePath)
(hasPathPermission(value.absolutePath) &&
(!value.operationCode || hasPermission(value.operationCode)))
)
.map((value) => {
if (value.children) {
@@ -31,6 +31,12 @@ export const getAuthRoute = (
}
return value
})
temp.push({
path: '',
absolutePath: '',
element: <Navigate to={temp[0].absolutePath} replace />
})
return temp
}
export const mapJsonToRoute = (jsonObject: RouteJsonObject[]): RouteObject[] => {