blob: 8391f9078117562ed8ea89790f35920413330f65 [file] [log] [blame]
San3yuan4d0e8032025-04-04 17:21:40 +08001import { Navigate, Outlet } from 'react-router-dom'
2import React from 'react'
3
4interface PrivateRouteProps {
5 isAllowed: boolean
6 redirectPath?: string
7 children?: React.ReactNode
8}
9
10const PrivateRoute = ({
11 isAllowed,
12 redirectPath = '/login',
13 children
14}: PrivateRouteProps) => {
15 if (!isAllowed) {
16 return <Navigate to={redirectPath} replace />
17 }
18
19 return children ? children : <Outlet />
20}
21
22export default PrivateRoute