Add Restaurant almost done
This commit is contained in:
25
src/components/PrivateRoute.js
Normal file
25
src/components/PrivateRoute.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import React from "react";
|
||||
import { useSelector } from "react-redux";
|
||||
import { Redirect, Route } from "react-router-dom";
|
||||
|
||||
export default function PrivateRoute({ component, ...rest }) {
|
||||
const loggedIn = useSelector((state) => state.data.loggedIn);
|
||||
|
||||
return (
|
||||
<Route
|
||||
{...rest}
|
||||
render={({ location }) =>
|
||||
loggedIn ? (
|
||||
component
|
||||
) : (
|
||||
<Redirect
|
||||
to={{
|
||||
pathname: "/login",
|
||||
state: { from: location },
|
||||
}}
|
||||
/>
|
||||
)
|
||||
}
|
||||
/>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user