I am passing props to the same component in two different ways.
Once by Route path:-
<Route path="/CreateProfile/:title" exact component={ProfileForm} />
Another by Link as:
<Table.Cell><Link to={{ // it will land to the same component ProfileForm
pathname: "/EditProfile",
props: {
profile : profile,
title: "Edit Profile"
}
}} >Edit Profile</Link></Table.Cell>
In my ProfileForm, I tried to read props as:-
useEffect(() => {
if(props.match.params.title){ // it gives no error.
setTitle(props.match.params.title);
}else if(props.location.props.title){ // gives error .props.title undefiened
setTitle(props.location.props.title);
}
// if(props.match.params.profile){
// setProfile(props.location.state.profile)
// }
if(props.location.props.profile){
setProfile(props.location.props.profile)
console.log("profile: "+props.location.props.profile)
}
}
else if(props.location.props.title)
gives an error when it comes from the Router. It is expected because I set props by Link. I noticed props.match.params.title
never gives any error whether it is set or not. So I wish to pass props by the match from Link so that both Route and Link works properly.
Is it possible to pass props by match? Or how do I solve this issue?