0
votes

I've tried a lot of examples from React Router documentation, Stackoverflow answers and posts on the web, but couldn't get anything working.

Here's what I have now:

<Link to={{
   pathname: "/project",
   state: { id: "id0" }
}}>Passing Props</Link>

and

<Route path="/project" component={Project}  />

and state is undefined here:

function Project(params) {
  console.log("passprops");
  console.log(params);
// state is undefined in params

I've also tried passing with "/project/:id" and render={(props) => } but it didn't work too.

How to pass props/params/state to a Route with Link in React Router 5.2.0?

1

1 Answers

1
votes

from my project

<Link to="/project/id1">Project</Link>



<Route path="/project/:id" component={Project}/>



function Project() {
  let { id } = useParams();
}