22 lines
477 B
JavaScript
22 lines
477 B
JavaScript
import React from "react";
|
|
import { Redirect, Route, useLocation } from "react-router-dom";
|
|
|
|
function PrivateRoute({ component: Component, isAuthorized, ...rest }) {
|
|
const location = useLocation();
|
|
|
|
return (
|
|
<Route
|
|
{...rest}
|
|
render={(props) =>
|
|
isAuthorized === true ? (
|
|
<Component {...props} />
|
|
) : (
|
|
<Redirect to={`/signin?redirect=${location.pathname}`} />
|
|
)
|
|
}
|
|
/>
|
|
);
|
|
}
|
|
|
|
export default PrivateRoute;
|