score:6

Accepted answer

If you are looking for a way to pass extra props to the PrivateRoute you can do:

const PrivateRoute = ({ component: Component, ...rest }) => (
  <Route
    {...rest}
    render={ (props) =>
      ( console.log(props.extra) || 1) ? (
        <Component {...props} {...rest} />
      ) : (
        <Redirect
          to={{
            pathname: "/login",
            state: { from: props.location }
          }}
        />
      )
    }
  />
);

then

<PrivateRoute exact path="/protected" component={Main} extra="Boo!"/>

and Main should now receive extra prop (together with path and exact).


Related Query

More Query from same tag