Big progress!
This commit is contained in:
@@ -1,40 +0,0 @@
|
||||
import React, {useEffect} from "react";
|
||||
import {useNavigate, useLocation, Outlet} from "react-router-dom";
|
||||
|
||||
function PrivateRoute({ component: Component, isAuthorized, ...rest }) {
|
||||
const location = useLocation();
|
||||
const navigate = useNavigate();
|
||||
|
||||
useEffect(() => {
|
||||
if (!isAuthorized) {
|
||||
navigate(`/signin?redirect=${location.pathname}`);
|
||||
}
|
||||
}, [isAuthorized, navigate]);
|
||||
|
||||
return <Outlet />;
|
||||
}
|
||||
|
||||
export default PrivateRoute;
|
||||
|
||||
|
||||
// import React, { useEffect } from 'react';
|
||||
// import { Outlet, useSearchParams, useNavigate } from 'react-router-dom';
|
||||
//
|
||||
// const PrivateRoute = ({ isAuthorized }) => {
|
||||
// const [searchParams] = useSearchParams();
|
||||
// const navigate = useNavigate();
|
||||
//
|
||||
// useEffect(() => {
|
||||
// if (!isAuthorized) {
|
||||
// console.log('is not authorized');
|
||||
// searchParams.set("redirect", window.location.pathname);
|
||||
// navigate(`/signin?${searchParams.toString()}`);
|
||||
// } else {
|
||||
// console.log('isAuthorized');
|
||||
// }
|
||||
// }, [isAuthorized, navigate, searchParams]);
|
||||
//
|
||||
// return <Outlet />;
|
||||
// }
|
||||
//
|
||||
// export default PrivateRoute;
|
||||
Reference in New Issue
Block a user