I have the following code :
const PrivateRoute = ({ component: Component, ...rest }) => {
return (<Route {...rest} render={(props) => (isAuthenticated() === true ? <Component {...props} /> : <Redirect to='/login' /> )} />)
}
but i dont understand how this works.. I call it like :
<PrivateRoute exact path = '/home' component={Home}></PrivateRoute>
it works , I just dont understand it. Where is props being passed in ? What is component: Component.
I would appreciate if someone could explain how this components works.
renderparameter inRoute. So if yourisAuthenticatedmethod returns true thenrenderwill be provided whatever component you passed otherwise it get theRedirectcomponent and hence redirect the user to login. If you pass any other props to thePrivateRoutethose will be passed to theRoutecomponent using rest parameter (developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…).