Tried to add a Protected Route for the Home page
This commit is contained in:
19
src/components/ProtectedRoute.js
Normal file
19
src/components/ProtectedRoute.js
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import { Navigate } from "react-router-dom"
|
||||||
|
import React from "react"
|
||||||
|
import Root from "../routes/Root"
|
||||||
|
|
||||||
|
export default function ProtectedRoute({ user, loading }) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{!loading ? (
|
||||||
|
user ? (
|
||||||
|
<Root />
|
||||||
|
) : (
|
||||||
|
<Navigate to="/login" />
|
||||||
|
)
|
||||||
|
) : (
|
||||||
|
<div>loading....</div>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user