I have the code below. I need to send props to Dashboard component.
<Router>
<Switch>
<RouteGuard
exact
path="/"
component={Dashboard}
/>
<Route
path="/login"
component={LoginPage}
/>
<Redirect to="/" />
</Switch>
</Router>
What I want to do is something like the code below.
<Route path="/dashboard">
<Dashboard isActive={isActive} handleClick={handleClick} />
</Route>
The code for my RouteGuard component is below.
const RouteGuard = ({ component: Component, ...rest }) => {
function hasJWT() {
let flag = false;
//check user has JWT token
localStorage.getItem("token") ? flag=true : flag=false
return flag
}
return (
<Route
{...rest}
render={props => (
hasJWT()
? <Component {...props} />
: <Redirect to={{ pathname: '/login' }} />
)}
/>
);
};