I am trying to receive the 'id' that is in the URI. But I am unable to collect it.
Route:
<Route path="/reports/:id" >
{!isLoggedIn ?
<Redirect to="/login" /> : <UserReport userData={userData} />
}
</Route>
Link:
<Link to={'/reports/'+employee.id}>
<span className="btn btn-sm btn-primary" style={{cursor:'pointer'}}>
Report <FontAwesomeIcon icon="history" />
</span>
</Link>
Component:
const UserReport = (props)=>{
return (
<div>
{props.match.params.id}
</div>
);
}
Error:
It says props.match is undefined
But when I try the component attribute in Route, it works
<Route path="/reports/:id" component={UserReport} >
Is it possible to do this the way I am trying? Please help..This is my first React project.