mirror of https://github.com/langgenius/dify.git
tweaks
This commit is contained in:
parent
479b813531
commit
093664757f
|
|
@ -1,9 +1,8 @@
|
|||
'use client'
|
||||
|
||||
import type { ReactNode } from 'react'
|
||||
import { useEffect } from 'react'
|
||||
import { useAppContext } from '@/context/app-context'
|
||||
import { usePathname, useRouter } from '@/next/navigation'
|
||||
import { redirect, usePathname } from '@/next/navigation'
|
||||
|
||||
const datasetOperatorRedirectRoutes = ['/apps', '/app', '/explore', '/tools'] as const
|
||||
|
||||
|
|
@ -12,20 +11,14 @@ const isPathUnderRoute = (pathname: string, route: string) => pathname === route
|
|||
export default function RoleRouteGuard({ children }: { children: ReactNode }) {
|
||||
const { isCurrentWorkspaceDatasetOperator, isLoadingCurrentWorkspace } = useAppContext()
|
||||
const pathname = usePathname()
|
||||
const router = useRouter()
|
||||
const shouldGuardRoute = datasetOperatorRedirectRoutes.some(route => isPathUnderRoute(pathname, route))
|
||||
const shouldRedirect = shouldGuardRoute && !isLoadingCurrentWorkspace && isCurrentWorkspaceDatasetOperator
|
||||
|
||||
useEffect(() => {
|
||||
if (shouldRedirect)
|
||||
router.replace('/datasets')
|
||||
}, [shouldRedirect, router])
|
||||
|
||||
if (shouldGuardRoute && isLoadingCurrentWorkspace)
|
||||
return null
|
||||
|
||||
if (shouldRedirect)
|
||||
return null
|
||||
return redirect('/datasets')
|
||||
|
||||
return <>{children}</>
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue